diff options
author | Manuel Carrasco Moñino <manolo@apache.org> | 2015-01-02 16:03:28 +0100 |
---|---|---|
committer | Manuel Carrasco Moñino <manolo@apache.org> | 2015-01-02 16:03:28 +0100 |
commit | 82c7f0d7d8c63c01f382e78d460e229644a9089f (patch) | |
tree | 524b71ea1ac2751cb27f3fdcb62d130464ba447c /gwtquery-core/src | |
parent | 26cc9ab92f71ffe2836c00764c1e0d92f9816642 (diff) | |
parent | d3e9bbafe0103a343d381942f056f587cb0c0cbf (diff) | |
download | gwtquery-82c7f0d7d8c63c01f382e78d460e229644a9089f.tar.gz gwtquery-82c7f0d7d8c63c01f382e78d460e229644a9089f.zip |
Merge pull request #329 from manolo/mcm_styling
Styling issues
Diffstat (limited to 'gwtquery-core/src')
152 files changed, 2709 insertions, 1980 deletions
diff --git a/gwtquery-core/src/main/code-style/gwt-checkstyle.xml b/gwtquery-core/src/main/code-style/gwt-checkstyle.xml new file mode 100644 index 00000000..04f8c3e8 --- /dev/null +++ b/gwtquery-core/src/main/code-style/gwt-checkstyle.xml @@ -0,0 +1,226 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + This configuration file was written by the eclipse-cs plugin configuration editor +--> +<!-- +Checkstyle-Configuration: GWT Checks +Description: + +--> +<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd"> +<module name="Checker"> + <property name="severity" value="warning"/> + <module name="RegexpHeader"> + <property name="fileExtensions" value="java"/> + <property name="severity" value="error"/> + <property name="header" value="^/\*[ ]*$\n^ \* Copyright 20(0[6789]|[12][0-9]), The gwtquery team\.$\n^ \*[ ]*$\n^ \* Licensed under the Apache License, Version 2\.0 \(the "License"\); you may not( use this file except)?$\n^ \* (use this file except )?in compliance with the License\. You may obtain a copy of( the License at)?$\n^ \* the License at$\n^ \*[ ]*$\n^ \* http://www\.apache\.org/licenses/LICENSE-2\.0$\n^ \*[ ]*\n \* Unless required by applicable law or agreed to in writing, software( distributed under the License)?$\n^ \* (distributed under the License )?is distributed on an "AS IS" BASIS, WITHOUT( WARRANTIES OR CONDITIONS OF ANY KIND, either express)?$\n^ \* (WARRANTIES OR CONDITIONS OF ANY KIND, either express )?or implied\. See the( License for the specific language governing permissions and limitations under)?$\n^ \* License for the specific language governing permissions and limitations under$\n^ \* the License\.$\n^ \*/$"/> + <property name="multiLines" value="6,13"/> + </module> + <module name="FileTabCharacter"> + <metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="no tabs"/> + <property name="fileExtensions" value="java"/> + <property name="severity" value="error"/> + </module> + <module name="TreeWalker"> + <property name="fileExtensions" value="java"/> + <module name="FileContentsHolder" /> + <module name="InterfaceIsType"> + <property name="severity" value="ignore"/> + </module> + <module name="RedundantImport"> + <property name="severity" value="error"/> + </module> + <module name="UnusedImports"> + <property name="severity" value="error"/> + </module> + <module name="JavadocType"> + <property name="severity" value="error"/> + <property name="scope" value="protected"/> + </module> + <module name="PackageName"> + <property name="severity" value="error"/> + <property name="format" value="^[a-z]+(\.[a-z][a-z0-9]{1,})*$"/> + </module> + <module name="ParameterName"> + <property name="severity" value="error"/> + </module> + <module name="LocalFinalVariableName"> + <property name="severity" value="error"/> + </module> + <module name="LocalVariableName"> + <property name="severity" value="error"/> + <property name="tokens" value="PARAMETER_DEF,VARIABLE_DEF"/> + </module> + <module name="LeftCurly"/> + <module name="RightCurly"/> + <module name="CovariantEquals"> + <property name="severity" value="error"/> + </module> + <module name="HiddenField"> + <property name="severity" value="error"/> + <property name="tokens" value="VARIABLE_DEF"/> + <property name="ignoreConstructorParameter" value="true"/> + <property name="ignoreSetter" value="true"/> + </module> + <module name="IllegalInstantiation"> + <property name="severity" value="error"/> + <property name="classes" value="java.lang.Boolean"/> + </module> + <module name="UpperEll"> + <metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="checking for 4l rather than 4L"/> + <property name="severity" value="error"/> + </module> + <module name="JavadocStyle"> + <metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Well formed java docs"/> + <property name="severity" value="info"/> + <property name="checkHtml" value="false"/> + <property name="tokens" value="CLASS_DEF,CTOR_DEF,INTERFACE_DEF,METHOD_DEF,VARIABLE_DEF"/> + </module> + <module name="JavadocMethod"> + <metadata name="com.atlassw.tools.eclipse.checkstyle.lastEnabledSeverity" value="info"/> + <property name="severity" value="info"/> + <property name="scope" value="protected"/> + <property name="allowUndeclaredRTE" value="true"/> + <property name="allowMissingParamTags" value="true"/> + <property name="allowMissingThrowsTags" value="true"/> + <property name="allowMissingReturnTag" value="true"/> + <property name="allowMissingJavadoc" value="true"/> + <property name="allowMissingPropertyJavadoc" value="true"/> + <property name="logLoadErrors" value="true"/> + <property name="tokens" value="METHOD_DEF"/> + </module> + <module name="ImportOrder"> + <property name="severity" value="error"/> + <property name="groups" value="com.google, com, junit, net,org, java,javax"/> + <property name="ordered" value="true"/> + <property name="separated" value="true"/> + <property name="option" value="top"/> + </module> + <module name="DefaultComesLast"> + <property name="severity" value="error"/> + </module> + <module name="MultipleStringLiterals"> + <property name="severity" value="info"/> + <property name="ignoreStringsRegexp" value=".{0,3}"/> + </module> + <module name="FallThrough"> + <property name="severity" value="error"/> + </module> + <module name="IllegalInstantiation"> + <property name="severity" value="error"/> + <property name="classes" value="Boolean"/> + </module> + <module name="Regexp"> + <metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="check that a space is left after a colon with an assembled error message"/> + <property name="severity" value="info"/> + <property name="format" value="[^:^"]:" .*+"/> + <property name="message" value="check that a space is left after a colon on an assembled error message"/> + <property name="illegalPattern" value="true"/> + </module> + <module name="Regexp"> + <metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="more than one blank line"/> + <property name="severity" value="info"/> + <property name="format" value="[\r]?[\n][ \t]*[\r]?[\n][ \t]*[\r]?[\n][ \t]*"/> + <property name="message" value="more than one blank line"/> + <property name="illegalPattern" value="true"/> + </module> + <module name="WhitespaceAround"> + <metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Must have spaces"/> + <property name="severity" value="error"/> + <property name="tokens" value="COLON,NOT_EQUAL,QUESTION,DIV,DIV_ASSIGN,BXOR,BXOR_ASSIGN,MINUS,LCURLY,STAR,STAR_ASSIGN,TYPE_EXTENSION_AND,BAND,LAND,BAND_ASSIGN,MOD,MOD_ASSIGN,PLUS,PLUS_ASSIGN,LT,SL,SL_ASSIGN,LE,ASSIGN,MINUS_ASSIGN,EQUAL,GT,GE,SR,SR_ASSIGN,BSR,BSR_ASSIGN,BOR,BOR_ASSIGN,LOR,LITERAL_ASSERT,LITERAL_ASSERT,LITERAL_CATCH,LITERAL_DO,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_FOR,LITERAL_IF,LITERAL_RETURN,SLIST,LITERAL_SYNCHRONIZED,LITERAL_TRY,LITERAL_WHILE"/> + </module> + <module name="Regexp"> + <metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="newline before }"/> + <property name="severity" value="error"/> + <property name="format" value="[\r]?[\n][ \t]*[\r]?[\n][ \t]+[}][ ]*[\n]"/> + <property name="message" value="newline before }"/> + <property name="illegalPattern" value="true"/> + </module> + <module name="ModifierOrder"> + <property name="severity" value="error"/> + </module> + <module name="AvoidStarImport"> + <property name="severity" value="error"/> + </module> + <module name="RegexpSinglelineJava"> + <metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="bad // comment"/> + <property name="severity" value="error"/> + <property name="format" value=" [/][/][A-z]"/> + <property name="message" value="// comments must be followed by a space and be on their own line"/> + </module> + <module name="EmptyStatement"> + <property name="severity" value="error"/> + </module> + <module name="MethodName"> + <property name="severity" value="error"/> + <property name="format" value="^[a-z$XJD:][a-zA-Z0-9$]*$"/> + </module> + <module name="MemberName"> + <metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Field names must start with [a-z], may not start with f[A-Z], and should not contain '_''s."/> + <property name="severity" value="error"/> + <property name="format" value="^([a-eg-z]|(f[a-z0-9]))[a-zA-Z0-9]*$"/> + </module> + <module name="TodoComment"> + <metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Author tags"/> + <property name="severity" value="error"/> + <property name="format" value="@author"/> + </module> + <module name="Regexp"> + <metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="No one line javadoc comments"/> + <property name="severity" value="error"/> + <property name="format" value="[/][*][*][^\n]*[*][/]"/> + <property name="message" value="No one line javadoc comments"/> + <property name="illegalPattern" value="true"/> + </module> + <module name="NoWhitespaceAfter"> + <property name="severity" value="error"/> + <property name="allowLineBreaks" value="false"/> + <property name="tokens" value="BNOT,DEC,DOT,INC,LNOT,UNARY_MINUS,UNARY_PLUS"/> + </module> + <module name="WhitespaceAfter"> + <property name="tokens" value="TYPECAST"/> + </module> + <module name="TypecastParenPad"> + <property name="severity" value="error"/> + <property name="tokens" value="RPAREN,TYPECAST"/> + </module> + <module name="ParenPad"/> + <module name="MethodParamPad"/> + <module name="NoWhitespaceBefore"> + <property name="severity" value="error"/> + <property name="tokens" value="SEMI,POST_DEC,POST_INC"/> + </module> + <module name="NoWhitespaceBefore"> + <property name="severity" value="error"/> + <property name="allowLineBreaks" value="true"/> + <property name="tokens" value="DOT"/> + </module> + <module name="RedundantModifier"/> + <module name="EqualsHashCode"/> + </module> + <module name="JavadocPackage"> + <property name="severity" value="ignore"/> + </module> + <module name="SuppressionCommentFilter"> + <property name="offCommentFormat" value="CHECKSTYLE_OFF"/> + <property name="onCommentFormat" value="CHECKSTYLE_ON"/> + </module> + <module name="SuppressionCommentFilter"> + <metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Avoid name checking"/> + <property name="offCommentFormat" value="CHECKSTYLE_NAMING_OFF"/> + <property name="onCommentFormat" value="CHECKSTYLE_NAMING_ON"/> + <property name="checkFormat" value="MethodName"/> + </module> + <module name="SuppressionCommentFilter"> + <metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Avoid name checking"/> + <property name="offCommentFormat" value="CHECKSTYLE_NAMING_OFF"/> + <property name="onCommentFormat" value="CHECKSTYLE_NAMING_ON"/> + <property name="checkFormat" value="MemberName"/> + </module> + <module name="SuppressionCommentFilter"> + <metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Avoid name checking"/> + <property name="offCommentFormat" value="CHECKSTYLE_NAMING_OFF"/> + <property name="onCommentFormat" value="CHECKSTYLE_NAMING_ON"/> + <property name="checkFormat" value="ParameterName"/> + </module> +</module> diff --git a/gwtquery-core/src/main/code-style/gwt-format.xml b/gwtquery-core/src/main/code-style/gwt-format.xml new file mode 100644 index 00000000..398c5d98 --- /dev/null +++ b/gwtquery-core/src/main/code-style/gwt-format.xml @@ -0,0 +1,279 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<profiles version="11"> +<profile kind="CodeFormatterProfile" name="GWT Format" version="11"> +<setting id="org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode" value="enabled"/> +<setting id="org.eclipse.jdt.core.compiler.codegen.targetPlatform" value="1.5"/> +<setting id="org.eclipse.jdt.core.compiler.compliance" value="1.5"/> +<setting id="org.eclipse.jdt.core.compiler.problem.assertIdentifier" value="error"/> +<setting id="org.eclipse.jdt.core.compiler.problem.enumIdentifier" value="error"/> +<setting id="org.eclipse.jdt.core.compiler.source" value="1.5"/> +<setting id="org.eclipse.jdt.core.formatter.align_type_members_on_columns" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_assignment" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_binary_expression" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_compact_if" value="48"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer" value="32"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_method_declaration" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_multiple_fields" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_imports" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_package" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_field" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_imports" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_member_type" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_method" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_package" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_import_groups" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_array_initializer" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_constant" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_method_declaration" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_switch" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_type_declaration" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.comment.format_block_comments" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.comment.format_html" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.comment.format_javadoc_comments" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.comment.format_line_comments" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.comment.format_source_code" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.comment.indent_parameter_description" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.comment.indent_root_tags" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="250"/> +<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.compact_else_if" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="2"/> +<setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer" value="2"/> +<setting id="org.eclipse.jdt.core.formatter.disabling_tag" value="@formatter:off"/> +<setting id="org.eclipse.jdt.core.formatter.enabling_tag" value="@formatter:on"/> +<setting id="org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.indent_empty_lines" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_block" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_body" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="2"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_label" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_binary_operator" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_unary_operator" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_binary_operator" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_ellipsis" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_unary_operator" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.join_lines_in_comments" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="100"/> +<setting id="org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="space"/> +<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="2"/> +<setting id="org.eclipse.jdt.core.formatter.use_on_off_tags" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.wrap_before_binary_operator" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested" value="false"/> +</profile> +</profiles> diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/Browser.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/Browser.java index 839a0cee..e8136e14 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/Browser.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/Browser.java @@ -15,8 +15,6 @@ */ package com.google.gwt.query.client; -import com.google.gwt.query.rebind.BrowserGenerator; - /** * This class is the equivalent to the jQuery.browser object in gQuery. * @@ -29,17 +27,17 @@ import com.google.gwt.query.rebind.BrowserGenerator; * Example: * <pre> if (GQuery.browser.ie6) { - // this code will be removed on non-ie6 permutations + // this code will be removed on non-ie6 permutations Window.alert("IE6"); } else if (!browser.webkit) { - // this code will be only in the webkit permutation + // this code will be only in the webkit permutation Window.alert("NOT WEBKIT"); - } + } * </pre> * */ public abstract class Browser { - + /** * @return true if ie6 */ @@ -65,24 +63,32 @@ public abstract class Browser { */ public final boolean opera = isOpera(); /** - * Maintained for jQuery compatibility + * Maintained for jQuery compatibility. * @return true if webkit * @deprecated use webkit() instead */ - @Deprecated + @Deprecated public final boolean safari = isWebkit(); /** * @return true if webkit */ public final boolean webkit = isWebkit(); - + protected abstract boolean isIe6(); + protected abstract boolean isIe8(); + protected abstract boolean isIe9(); + protected abstract boolean isIe10(); + protected abstract boolean isIe11(); + protected abstract boolean isMozilla(); + protected abstract boolean isMsie(); + protected abstract boolean isOpera(); + protected abstract boolean isWebkit(); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/Console.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/Console.java index dcd0300d..ec2afba9 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/Console.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/Console.java @@ -15,7 +15,6 @@ */ package com.google.gwt.query.client; - /** * This interface represents the Window.console object. */ diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/Function.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/Function.java index b094ebf8..063aaf38 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/Function.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/Function.java @@ -30,13 +30,13 @@ public abstract class Function { private Event event = null; private int index = -1; protected Object[] arguments = new Object[0]; - + /** * Utility method to get a string representation with the content * of the arguments array. It recursively visits arrays and inspect * object to print an appropriate representation of them. * - * It is very useful to debug arguments passed in nested promises. + * It is very useful to debug arguments passed in nested promises. * * It is protected so as it can be used in Inner functions. * @@ -51,33 +51,34 @@ public abstract class Function { protected String dumpArguments() { return dumpArguments(arguments, "\n"); } - + private String dumpArguments(Object[] arguments, String sep) { StringBuilder b = new StringBuilder(); - for (int i = 0, l = arguments.length; i < l; i++ ) { + for (int i = 0, l = arguments.length; i < l; i++) { b.append("[").append(i).append("]"); Object o = arguments[i]; if (o == null) { b.append(" null"); } else if (o.getClass().isArray()) { - b.append(dumpArguments((Object[])o, sep + " ")); + b.append(dumpArguments((Object[]) o, sep + " ")); } else if (o instanceof JavaScriptObject) { - JavaScriptObject jso = (JavaScriptObject)o; + JavaScriptObject jso = (JavaScriptObject) o; if (JsUtils.isElement(jso)) { b.append("(Element) ").append(jso.toString()); } else { - b.append("(JSO) ").append(jso.<Properties>cast().toJsonString()); + b.append("(JSO) ").append(jso.<Properties> cast().toJsonString()); } } else { b.append("(").append(o.getClass().getName()).append(") ").append(o); } - if (i < l-1) b.append(sep); + if (i < l - 1) + b.append(sep); } return b.toString(); } public <T extends com.google.gwt.dom.client.Element> T getElement() { - return element.<T>cast(); + return element.<T> cast(); } public <T extends com.google.gwt.dom.client.Element> Function setElement(T e) { @@ -87,7 +88,8 @@ public abstract class Function { public Function setEvent(Event e) { event = e; - element = e != null ? e.getCurrentEventTarget().<com.google.gwt.dom.client.Element>cast() : null; + element = + e != null ? e.getCurrentEventTarget().<com.google.gwt.dom.client.Element> cast() : null; return this; } @@ -99,7 +101,7 @@ public abstract class Function { index = i; return this; } - + /** * @deprecated use getArguments instead. */ @@ -111,17 +113,18 @@ public abstract class Function { public Object[] getArguments() { return arguments; } - + /** - * Set the list of arguments to be passed to the function + * Set the list of arguments to be passed to the function. */ - public Function setArguments(Object...arguments) { + public Function setArguments(Object... arguments) { this.arguments = arguments; return this; } /** - * Return the first element of the arguments list + * Return the first element of the arguments list. + * * @deprecated use getArgument(idx) instead. */ @Deprecated @@ -130,7 +133,7 @@ public abstract class Function { } /** - * @deprecated use getArgument instead + * @deprecated use getArgument instead. */ @Deprecated public Object getDataObject(int idx) { @@ -144,9 +147,9 @@ public abstract class Function { */ @SuppressWarnings("unchecked") public <T extends JavaScriptObject> T getArgumentJSO(int argIdx, int pos) { - return (T)getArgument(argIdx, pos, JavaScriptObject.class); + return (T) getArgument(argIdx, pos, JavaScriptObject.class); } - + /** * Utility method for safety getting a JavaScriptObject present at a certain * position in the list of arguments. @@ -154,20 +157,20 @@ public abstract class Function { public <T extends JavaScriptObject> T getArgumentJSO(int idx) { return getArgumentJSO(-1, idx); } - + /** * Utility method for safety getting an array present at a certain * position in the list of arguments. * - * Useful for Deferred chains where result of each resolved + * Useful for Deferred chains where result of each resolved * promise is set as an array in the arguments list. * * Always returns an array. */ public Object[] getArgumentArray(int idx) { - Object o = idx < 0 ? arguments: getArgument(idx); + Object o = idx < 0 ? arguments : getArgument(idx); if (o != null) { - return o.getClass().isArray() ? (Object[])o : new Object[]{o}; + return o.getClass().isArray() ? (Object[]) o : new Object[] {o}; } else if (idx == 0) { return arguments; } @@ -178,27 +181,27 @@ public abstract class Function { * Return the argument in the position idx or null if it doesn't exist. * * Note: if the return type doesn't match the object, you - * will get a casting exception. + * will get a casting exception. */ public <T> T getArgument(int idx) { return getArgument(-1, idx, null); } /** - * Convenience alias for the getArguments(idx) method thought just to + * Convenience alias for the getArguments(idx) method thought just to * make gQuery code look closed to jQuery. */ public <T> T arguments(int idx) { return getArgument(idx); } - + /** - * Convenience alias for the getArguments(argIdx, pos) method; + * Convenience alias for the getArguments(argIdx, pos) method. */ public <T> T arguments(int argIdx, int pos) { return getArgument(argIdx, pos); } - + /** * Safety return the argument in the position idx. * @@ -208,7 +211,7 @@ public abstract class Function { public <T> T getArgument(int argIdx, int pos) { return getArgument(argIdx, pos, null); } - + /** * Safety return the argument in the position idx. * @@ -223,13 +226,13 @@ public abstract class Function { * Utility method for safety getting an object present at a certain * position in the list of arguments composed by arrays. * - * Useful for Deferred chains where result of each resolved + * Useful for Deferred chains where result of each resolved * promise is set as an array in the arguments list. * * When the object found in the array doesn't match the type required it returns a null. * * Note: If type is null, we don't check the class of the object found andd you could - * eventually get a casting exception. + * eventually get a casting exception. * */ @SuppressWarnings("unchecked") @@ -237,21 +240,20 @@ public abstract class Function { Object[] objs = getArgumentArray(argIdx); Object o = objs.length > pos ? objs[pos] : null; if (o != null && ( - // When type is null we don't safety check - type == null || - // The object is an instance of the type requested - o.getClass() == type || - // Overlay types - type == JavaScriptObject.class && o instanceof JavaScriptObject - )) { - return (T)o; + // When type is null we don't safety check + type == null || + // The object is an instance of the type requested + o.getClass() == type || + // Overlay types + type == JavaScriptObject.class && o instanceof JavaScriptObject + )) { + return (T) o; } return null; } - /** - * @deprecated use: getArgument() + * @deprecated use: getArgument() instead. */ @Deprecated public Properties getDataProperties() { @@ -259,7 +261,7 @@ public abstract class Function { } /** - * @deprecated use: getArgument(idx) + * @deprecated use: getArgument(idx) instead. */ @Deprecated public Properties getDataProperties(int idx) { @@ -267,7 +269,7 @@ public abstract class Function { } /** - * @deprecated use: setArguments() + * @deprecated use: setArguments() instead. */ @Deprecated public void setData(boolean b) { @@ -275,18 +277,18 @@ public abstract class Function { } /** - * @deprecated use: setArguments() + * @deprecated use: setArguments() instead. */ @Deprecated public void setData(double b) { setArguments(b); } - + /** - * @deprecated use use setArguments instead + * @deprecated use use setArguments instead. */ @Deprecated - public void setData(Object...arguments) { + public void setData(Object... arguments) { setArguments(arguments); } @@ -299,7 +301,9 @@ public abstract class Function { } /** - * Return the index in a loop execution. Used in GQuery.each() + * Return the index in a loop execution. + * + * Used in GQuery.each() */ public int getIndex() { return index; @@ -313,8 +317,8 @@ public abstract class Function { */ public void cancel(com.google.gwt.dom.client.Element e) { setElement(e); - // This has to be the order of calls - cancel(e.<com.google.gwt.user.client.Element>cast()); + // This has to be the order of calls + cancel(e.<com.google.gwt.user.client.Element> cast()); } /** @@ -347,7 +351,7 @@ public abstract class Function { setElement(e); setIndex(i); // This has to be the order of calls - return f(e.<com.google.gwt.user.client.Element>cast(), i); + return f(e.<com.google.gwt.user.client.Element> cast(), i); } /** @@ -362,10 +366,10 @@ public abstract class Function { setElement(e); setIndex(i); Widget w = GQuery.getAssociatedWidget(e); - if (w != null){ + if (w != null) { f(w, i); } else { - f(e.<com.google.gwt.dom.client.Element>cast()); + f(e.<com.google.gwt.dom.client.Element> cast()); } return null; } @@ -386,7 +390,7 @@ public abstract class Function { } /** - * Override this method for bound callbacks + * Override this method for bound callbacks. */ public Object f(Object... args) { setArguments(args); @@ -395,24 +399,24 @@ public abstract class Function { } /** - * Override this method for bound callbacks + * Override this method for bound callbacks. */ public void f(int i, Object arg) { - f(i, new Object[]{arg}); + f(i, new Object[] {arg}); } /** - * Override this method for bound callbacks + * Override this method for bound callbacks. */ public void f(int i, Object... args) { setIndex(i); setArguments(args); if (args.length == 1 && args[0] instanceof JavaScriptObject) { - if (JsUtils.isElement((JavaScriptObject)args[0])) { - setElement((com.google.gwt.dom.client.Element)args[0]); + if (JsUtils.isElement((JavaScriptObject) args[0])) { + setElement((com.google.gwt.dom.client.Element) args[0]); f(getElement(), i); - } else if (JsUtils.isEvent((JavaScriptObject)args[0])) { - setEvent((Event)args[0]); + } else if (JsUtils.isEvent((JavaScriptObject) args[0])) { + setEvent((Event) args[0]); f(getEvent()); } else { f(); @@ -449,8 +453,8 @@ public abstract class Function { */ public void f(com.google.gwt.dom.client.Element e) { setElement(e); - // This has to be the order of calls - f(e.<com.google.gwt.user.client.Element>cast()); + // This has to be the order of calls + f(e.<com.google.gwt.user.client.Element> cast()); } /** @@ -460,11 +464,12 @@ public abstract class Function { * @param elem takes a com.google.gwt.user.client.Element */ private boolean loop = false; + @Deprecated public void f(com.google.gwt.user.client.Element e) { setElement(e); Widget w = e != null ? GQuery.getAssociatedWidget(e) : null; - if (w != null){ + if (w != null) { loop = true; f(w); } else { @@ -480,13 +485,13 @@ public abstract class Function { * 'public void f()' or 'public void f(Element e)' to handle these elements and * avoid a runtime exception. */ - public void f(Widget w){ + public void f(Widget w) { setElement(w.getElement()); if (loop) { loop = false; f(); } else { - f(w.getElement().<com.google.gwt.dom.client.Element>cast()); + f(w.getElement().<com.google.gwt.dom.client.Element> cast()); } } @@ -502,16 +507,16 @@ public abstract class Function { /** * Methods fe(...) should be used from asynchronous contexts so as we can * catch the exception and send it to the GWT UncaughtExceptionHandler - * They are intentionally final to avoid override them + * They are intentionally final to avoid override them. */ public final void fe(Object arg) { - fe(new Object[]{arg}); + fe(new Object[] {arg}); } /** * Methods fe(...) should be used from asynchronous contexts so as we can * catch the exception and send it to the GWT UncaughtExceptionHandler - * They are intentionally final to avoid override them + * They are intentionally final to avoid override them. */ public final Object fe(Object... args) { if (GWT.getUncaughtExceptionHandler() != null) { @@ -528,7 +533,7 @@ public abstract class Function { /** * Methods fe(...) should be used from asynchronous contexts so as we can * catch the exception and send it to the GWT UncaughtExceptionHandler - * They are intentionally final to avoid override them + * They are intentionally final to avoid override them. */ public final boolean fe(Event ev, Object... args) { if (GWT.getUncaughtExceptionHandler() != null) { @@ -545,17 +550,17 @@ public abstract class Function { /** * Methods fe(...) should be used from asynchronous contexts so as we can * catch the exception and send it to the GWT UncaughtExceptionHandler - * They are intentionally final to avoid override them + * They are intentionally final to avoid override them. */ public final void fe(com.google.gwt.dom.client.Element elem) { if (GWT.getUncaughtExceptionHandler() != null) { try { - f(elem.<com.google.gwt.dom.client.Element>cast()); + f(elem.<com.google.gwt.dom.client.Element> cast()); } catch (Exception e) { GWT.getUncaughtExceptionHandler().onUncaughtException(e); } return; } - f(elem.<com.google.gwt.dom.client.Element>cast()); + f(elem.<com.google.gwt.dom.client.Element> cast()); } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQ.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQ.java index 380c57ef..b32fbeb2 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQ.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQ.java @@ -15,11 +15,6 @@ */ package com.google.gwt.query.client; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import org.apache.http.MethodNotSupportedException; - import com.google.gwt.query.client.builders.JsonBuilder; import com.google.gwt.query.client.builders.JsonFactory; import com.google.gwt.query.client.plugins.ajax.Ajax.AjaxTransport; @@ -27,6 +22,9 @@ import com.google.gwt.query.client.plugins.ajax.AjaxTransportJs; import com.google.gwt.query.vm.AjaxTransportJre; import com.google.gwt.query.vm.JsonFactoryJre; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + /** * A set of useful methods for gQuery which can be run in browser or JVM. */ @@ -43,7 +41,7 @@ public abstract class GQ { } /** - * Create an instance of a JsonBuilder object whose type is <T> + * Create an instance of a JsonBuilder object whose type is <T>. */ public static <T extends JsonBuilder> T create(Class<T> clz) { return getFactory().create(clz); @@ -91,7 +89,7 @@ public abstract class GQ { /** * Return the appropriate transport implementation depending on the runtime - * environment: browser or JVM + * environment: browser or JVM. */ public static AjaxTransport getAjaxTransport() { initFactory(); @@ -119,7 +117,7 @@ public abstract class GQ { if (jsonFactory == null) { try { // We use reflection because the server side should not - // depend on gwt-servlet nor gwt-dev. Hence if GWT is not + // depend on gwt-servlet nor gwt-dev. Hence if GWT is not // in our classpath means that we are in server side, otherwise // we use GWT to figure out if we are running devmode. // This is run once, so no performance issues to worry about. @@ -131,7 +129,7 @@ public abstract class GQ { // We are running DevMode, so create Js versions of the factories method = gwt.getMethod("create", Class.class); ret = method.invoke(null, - new Object[] {JsonFactory.class}); + new Object[] {JsonFactory.class}); jsonFactory = (JsonFactory) ret; ajaxTransport = new AjaxTransportJs(); return; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java index d5fb0d99..0f9faadf 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java @@ -34,9 +34,7 @@ import com.google.gwt.dom.client.NodeList; import com.google.gwt.dom.client.OptionElement; import com.google.gwt.dom.client.SelectElement; import com.google.gwt.dom.client.Style.Display; -import com.google.gwt.dom.client.Style.HasCssName; import com.google.gwt.dom.client.TextAreaElement; -import com.google.gwt.query.client.css.CSS; import com.google.gwt.query.client.css.HasCssValue; import com.google.gwt.query.client.css.TakesCssValue; import com.google.gwt.query.client.css.TakesCssValue.CssSetter; @@ -72,7 +70,6 @@ import com.google.gwt.user.client.ui.Widget; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Map; /** * GwtQuery is a GWT clone of the popular jQuery library. @@ -105,7 +102,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { } /** - * Class used internally to create DOM element from html snippet + * Class used internally to create DOM element from html snippet. */ private static class TagWrapper { public static final TagWrapper DEFAULT = new TagWrapper(0, "", ""); @@ -151,7 +148,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { public static final Document document = GWT.isClient() ? Document.get() : null; /** - * Static reference Effects plugin + * Static reference Effects plugin. */ public static Class<Effects> Effects = com.google.gwt.query.client.plugins.Effects.Effects; @@ -161,7 +158,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { protected static SelectorEngine engine; /** - * Static reference Events plugin + * Static reference Events plugin. */ public static Class<Events> Events = com.google.gwt.query.client.plugins.Events.Events; @@ -178,7 +175,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { // Sizzle POS regex : usefull in some methods // TODO: Share this static with SelectorEngineSizzle - private static RegExp posRegex = RegExp.compile("^:(nth|eq|gt|lt|first|last|even|odd)(?:\\((\\d*)\\))?(?=[^\\-]|$)$"); + private static RegExp posRegex = RegExp + .compile("^:(nth|eq|gt|lt|first|last|even|odd)(?:\\((\\d*)\\))?(?=[^\\-]|$)$"); /** * Implementation class used for style manipulations. @@ -188,14 +186,15 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { private static RegExp tagNameRegex = RegExp.compile("<([\\w:-]+)"); /** - * Static reference to the Widgets plugin + * Static reference to the Widgets plugin. */ public static Class<Widgets> Widgets = com.google.gwt.query.client.plugins.Widgets.Widgets; /** * The window object. */ - public static final Element window = GWT.isClient() ? ScriptInjector.TOP_WINDOW.<Element>cast() : null; + public static final Element window = GWT.isClient() ? ScriptInjector.TOP_WINDOW.<Element> cast() + : null; private static Element windowData = null; @@ -255,15 +254,15 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { } return JsUtils.isWindow(jso) ? $(jso.<Element> cast()) : - JsUtils.isElement(jso) ? $(jso.<Element> cast()) : - JsUtils.isEvent(jso) ? $(jso.<Event> cast()) : - JsUtils.isNodeList(jso) ? $(jso.<NodeList<Element>> cast()) : - $(jso.<Element> cast()); + JsUtils.isElement(jso) ? $(jso.<Element> cast()) : + JsUtils.isEvent(jso) ? $(jso.<Event> cast()) : + JsUtils.isNodeList(jso) ? $(jso.<NodeList<Element>> cast()) : + $(jso.<Element> cast()); } /** * Wrap a GQuery around any object, supported objects are: - * String, GQuery, Function, Widget, JavaScriptObject + * String, GQuery, Function, Widget, JavaScriptObject. * * In the case of string, we accept a CSS selector which is then used to match a set of * elements, or a raw HTML to create a GQuery element containing those elements. Xpath @@ -277,31 +276,32 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { public static GQuery $(Object o) { if (o != null) { if (o instanceof String) { - return $((String)o); + return $((String) o); } if (o instanceof GQuery) { - return (GQuery)o; + return (GQuery) o; } if (o instanceof Function) { - return $((Function)o); + return $((Function) o); } if (JsUtils.isElement(o)) { - return $(JsUtils.<Element>cast(o)); + return $(JsUtils.<Element> cast(o)); } if (o instanceof JavaScriptObject) { - return $((JavaScriptObject)o); + return $((JavaScriptObject) o); } if (o instanceof IsWidget) { return $(Arrays.asList(o)); } - console.log("Error: GQuery.$(Object o) could not wrap the type : ", o.getClass().getName(), o); + console + .log("Error: GQuery.$(Object o) could not wrap the type : ", o.getClass().getName(), o); } return $(); } /** * Create a new GQuery given a list of {@link com.google.gwt.dom.client.Node} or - * {@link com.google.gwt.user.client.ui.IsWidget} + * {@link com.google.gwt.user.client.ui.IsWidget}. */ public static GQuery $(List<?> nodesOrWidgets) { JsNodeArray elms = JsNodeArray.create(); @@ -310,7 +310,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { if (o instanceof Node) { elms.addNode((Node) o); } else if (o instanceof IsWidget) { - elms.addNode(((IsWidget)o).asWidget().getElement()); + elms.addNode(((IsWidget) o).asWidget().getElement()); } } } @@ -497,8 +497,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { return // return all nodes added to the wrapper $(n.getChildNodes()) - // detach nodes from their temporary parent - .remove(null, false); + // detach nodes from their temporary parent + .remove(null, false); } /** @@ -549,7 +549,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { } /** - * Execute a function around each object + * Execute a function around each object. */ public static void each(JsArrayMixed objects, Function f) { for (int i = 0, l = objects.length(); i < l; i++) { @@ -558,7 +558,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { } /** - * Execute a function around each object + * Execute a function around each object. */ public static <T> void each(List<T> objects, Function f) { for (int i = 0, l = objects.size(); i < l; i++) { @@ -567,7 +567,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { } /** - * Execute a function around each object + * Execute a function around each object. */ public static <T> void each(T[] objects, Function f) { for (int i = 0, l = objects.length; i < l; i++) { @@ -696,9 +696,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { wrapperMap.put("td", trWrapper); wrapperMap.put("th", trWrapper); wrapperMap.put("col", new TagWrapper(2, "<table><tbody></tbody><colgroup>", - "</colgroup></table>")); + "</colgroup></table>")); wrapperMap.put("area", new TagWrapper(1, "<map>", "</map>")); - } private static GQuery innerHtml(String html, Document doc) { @@ -717,7 +716,6 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { } } - /** * Return a lazy version of the GQuery interface. Lazy function calls are simply queued up and not * executed immediately. @@ -769,7 +767,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { /** * A constructor function that returns a chainable utility object with methods to register * multiple callbacks into callback queues, invoke callback queues, and relay the success - * or failure state of any synchronous or asynchronous function + * or failure state of any synchronous or asynchronous function. */ public static Promise.Deferred Deferred() { return new Deferred(); @@ -783,24 +781,24 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { } private static native void scrollIntoViewImpl(Node n) /*-{ - if (n) - n.scrollIntoView() + if (n) + n.scrollIntoView() }-*/; private static native void setElementValue(Element e, String value) /*-{ - e.value = value; + e.value = value; }-*/; protected Node currentContext; protected String currentSelector; /** - * Immutable array of matched elements, modify this using setArray + * Immutable array of matched elements, modify this using setArray. */ private Element[] elements = new Element[0]; /** - * The nodeList of matched elements, modify this using setArray + * The nodeList of matched elements, modify this using setArray. */ // TODO: remove this and use elements, change return type of get() private NodeList<Element> nodeList = JavaScriptObject.createArray().cast(); @@ -952,11 +950,10 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * * NOTE: The ability of animating attribute values is only available in gquery but not jquery * - * * Example: * * <pre class="code"> - * //move the element from its original position to left:500px + * // move the element from its original position to left:500px * $("#foo").animate("left:'500'"); * * // Change the width html attribute of a table, note the symbol '$' to @@ -973,7 +970,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * Example: * * <pre class="code"> - * //move the element from its original position to 500px to the left for 500ms and + * // move the element from its original position to 500px to the left for 500ms and * // change the background color of the element at the end of the animation * * $("#foo").animate("left:'+=500'", new Function(){ @@ -1013,11 +1010,10 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * * NOTE: The ability of animating attribute values is only available in gquery but not jquery * - * * Example: * * <pre class="code"> - * //move the element from its original position to left:500px for 500ms using a swing easing + * // move the element from its original position to left:500px for 500ms using a swing easing * $("#foo").animate("left:'500'", 500, Easing.SWING); * * // Change the width html attribute of a table, note the symbol '$' to @@ -1035,8 +1031,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * Example: * * <pre class="code"> - * //move the element from its original position to 500px to the left and 5OOpx down for 400ms. - * //use a swing easing function for the transition + * // move the element from its original position to 500px to the left and 5OOpx down for 400ms. + * // use a swing easing function for the transition * $("#foo").animate(Properties.create("{top:'+=500px',left:'+=500px'}"), 400, Easing.SWING); * </pre> * @@ -1070,11 +1066,10 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * * NOTE: The ability of animating attribute values is only available in gquery but not jquery * - * * Example: * * <pre class="code"> - * //move the element from its original position to left:500px for 500ms + * // move the element from its original position to left:500px for 500ms * $("#foo").animate("left:'500'", 500); * * // Change the width html attribute of a table, note the symbol '$' to @@ -1092,7 +1087,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * Example: * * <pre class="code"> - * //move the element from its original position to 500px to the left for 1000ms and + * // move the element from its original position to 500px to the left for 1000ms and * // change the background color of the element at the end of the animation * $("#foo").animate("left:'+=500'", 1000, new Function(){ * public void f(Element e){ @@ -1101,7 +1096,6 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * }); * </pre> * - * * For color css properties, values can be specified via hexadecimal or rgb or literal values. * * Example: @@ -1110,10 +1104,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * $("#foo").animate("backgroundColor:'red', color:'#ffffff', borderColor:'rgb(129, 0, 70)', 1000"); * </pre> * - * - * @param prop the property to animate : "cssName:'value'" - * @param funcs an array of {@link Function} called once the animation is complete - * @param duration the duration in milliseconds of the animation + * @param stringOrProperties the set of properties to animate : "cssName:'value'" + * @param funcs an array of {@link Function} called once the animation is complete. */ public GQuery animate(Object stringOrProperties, int duration, Function... funcs) { return as(Effects).animate(stringOrProperties, duration, funcs); @@ -1188,11 +1180,11 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { public <T extends GQuery> T as(Class<T> plugin) { // GQuery is not a plugin for itself if (plugin == GQUERY) { - return (T)this; + return (T) this; } else if (plugins != null) { Plugin<?> p = plugins.get(plugin); if (p != null) { - return (T)p.init(this); + return (T) p.init(this); } } throw new RuntimeException("No plugin registered for class " + plugin.getName()); @@ -1287,7 +1279,6 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * The event handlers are passed as Functions that you can use to prevent default behavior. To * stop both default action and event bubbling, the function event handler has to return false. * - * */ public GQuery bind(int eventbits, final Function... funcs) { return as(Events).bind(eventbits, null, funcs); @@ -1312,7 +1303,6 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * The event handlers are passed as Functions that you can use to prevent default behavior. To * stop both default action and event bubbling, the function event handler has to return false. * - * */ public GQuery bind(String eventType, final Function... funcs) { return as(Events).bind(eventType, null, funcs); @@ -1476,7 +1466,6 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { } return $(unique(result)); - } /** @@ -1582,7 +1571,6 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * property defined in {@link CSS} class and call the {@link TakesCssValue#with(HasCssName)} * method on it. * - * * ex : * * <pre class="code"> @@ -1720,7 +1708,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { */ @SuppressWarnings("unchecked") public <T> T data(String name) { - return isEmpty() ? null : (T)data(get(0), name, null); + return isEmpty() ? null : (T) data(get(0), name, null); } /** @@ -2028,7 +2016,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { /** * Remove all event handlers previously attached using {@link #live(String, Function)}. In order * for this method to function correctly, the selector used with it must match exactly the - * selector initially used with {@link #live(String, Function)} + * selector initially used with {@link #live(String, Function)}. + * * @deprecated use {@link #off(String, String)} instead */ public GQuery die() { @@ -2038,7 +2027,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { /** * Remove an event handlers previously attached using {@link #live(int, Function)} In order for * this method to function correctly, the selector used with it must match exactly the selector - * initially used with {@link #live(int, Function)} + * initially used with {@link #live(int, Function)}. * @deprecated use {@link #off(String)} */ public GQuery die(int eventbits) { @@ -2048,7 +2037,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { /** * Remove an event handlers previously attached using {@link #live(String, Function)} In order for * this method to function correctly, the selector used with it must match exactly the selector - * initially used with {@link #live(String, Function)} + * initially used with {@link #live(String, Function)}. */ public GQuery die(String eventName) { return as(Events).die(eventName); @@ -2391,10 +2380,10 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { } private native Element getPreviousSiblingElement(Element elem) /*-{ - var sib = elem.previousSibling; - while (sib && sib.nodeType != 1) - sib = sib.previousSibling; - return sib; + var sib = elem.previousSibling; + while (sib && sib.nodeType != 1) + sib = sib.previousSibling; + return sib; }-*/; /** @@ -2654,7 +2643,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { } /** - * Return true if the first element is visible.isVisible + * Return true if the first element is visible.isVisible. */ public boolean isVisible() { return isEmpty() ? false : getStyleImpl().isVisible(get(0)); @@ -2749,7 +2738,6 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * Attach a handler for this event to all elements which match the current selector, now and in * the future. * <p> - * <p> * Ex : * * <pre> @@ -2804,7 +2792,6 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * Attach a handler for this event to all elements which match the current selector, now and in * the future. The <code>data</code> parameter allows us to pass data to the handler. * <p> - * <p> * Ex : * * <pre> @@ -3088,7 +3075,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { /** * Get all following siblings of each element up to but not including the element matched by the - * GQuery object, filtered by a selector + * GQuery object, filtered by a selector. * * @return */ @@ -3158,23 +3145,23 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * Set the current coordinates of every element in the set of matched elements, relative to the document. */ public GQuery offset(int top, int left) { - for (Element element : elements()){ - GQuery $element = $(element); + for (Element element : elements()) { + GQuery g = $(element); - String position = $element.css("position", true); + String position = g.css("position", true); if ("static".equals(position)) { css("position", "relative"); } - Offset curOffset = $element.offset(); - String curCSSTop = $element.css("top", true); - String curCSSLeft = $element.css("left", true); + Offset curOffset = g.offset(); + String curCSSTop = g.css("top", true); + String curCSSLeft = g.css("left", true); long curTop = 0; long curLeft = 0; - if (("absolute".equals(position) || "fixed".equals(position)) && ("auto".equals(curCSSTop) || "auto".equals - (curCSSLeft))) { - Offset curPosition = $element.position(); + if (("absolute".equals(position) || "fixed".equals(position)) + && ("auto".equals(curCSSTop) || "auto".equals(curCSSLeft))) { + Offset curPosition = g.position(); curTop = curPosition.top; curLeft = curPosition.left; } else { @@ -3194,7 +3181,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { long newTop = top - curOffset.top + curTop; long newLeft = left - curOffset.left + curLeft; - $element.css("top", "" + newTop).css("left", "" + newLeft); + g.css("top", "" + newTop).css("left", "" + newLeft); } return this; @@ -3262,21 +3249,21 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { } /** - * Remove an event handler + * Remove an event handler. */ public GQuery off(String eventName) { return unbind(eventName, null); } /** - * Remove an event handler + * Remove an event handler. */ public GQuery off(String eventName, Function f) { return unbind(eventName, f); } /** - * Remove an event handler + * Remove an event handler. */ public GQuery off(String eventName, String selector) { if (selector == null || selector.isEmpty()) { @@ -3315,7 +3302,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { return 0; } // height including padding and border - int outerHeight = (int)cur("offsetHeight", true); + int outerHeight = (int) cur("offsetHeight", true); if (includeMargin) { outerHeight += cur("marginTop", true) + cur("marginBottom", true); } @@ -3339,7 +3326,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { return 0; } // width including padding and border - int outerWidth = (int)cur("offsetWidth", true); + int outerWidth = (int) cur("offsetWidth", true); if (includeMargin) { outerWidth += cur("marginRight", true) + cur("marginLeft", true); } @@ -3390,7 +3377,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * including the element matched by the selector. */ public GQuery parentsUntil(final String selector) { - return parentsUntil(new Predicate(){ + return parentsUntil(new Predicate() { @Override public <T> boolean f(T e, int index) { return selector != null && $(e).is(selector); @@ -3670,7 +3657,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { */ public <T> T prop(String key) { assert key != null : "Key is null"; - return isEmpty() ? null : JsUtils.<T>prop(get(0), key); + return isEmpty() ? null : JsUtils.<T> prop(get(0), key); } /** @@ -3685,7 +3672,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { */ public <T> T prop(String key, Class<? extends T> clz) { assert key != null : "Key is null"; - return isEmpty() ? null : JsUtils.<T>prop(get(0), key, clz); + return isEmpty() ? null : JsUtils.<T> prop(get(0), key, clz); } /** @@ -3943,7 +3930,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { */ public GQuery removeProp(String name) { for (Element e : elements) { - e.<JsCache>cast().delete(name); + e.<JsCache> cast().delete(name); } return this; } @@ -3973,9 +3960,9 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { List<Element> newElements = new ArrayList<Element>(); for (int i = 0, l = target.size(); i < l; i++) { - GQuery _this = (i > 0 && mustBeCloned) ? this.clone() : this; - $(target.get(i)).replaceWith(_this); - newElements.addAll(Arrays.asList(_this.elements)); + GQuery that = (i > 0 && mustBeCloned) ? this.clone() : this; + $(target.get(i)).replaceWith(that); + newElements.addAll(Arrays.asList(that.elements)); } return $(newElements); } @@ -4020,7 +4007,6 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { $(el).remove(); } return this; - } /** @@ -4100,8 +4086,9 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { * Scrolls the first matched element into view. */ public GQuery scrollIntoView() { - if (!isEmpty()) + if (!isEmpty()) { scrollIntoViewImpl(get(0)); + } return this; } @@ -4241,7 +4228,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { } /** - * Make all matched elements visible + * Make all matched elements visible. */ public GQuery show() { for (Element e : elements) { @@ -4529,9 +4516,9 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { elStr = JsUtils.isXML(e) ? JsUtils.XML2String(e) : e.getString(); } catch (Exception e2) { elStr = - "< " + (e == null ? "null" : e.getNodeName()) - + "(gquery, error getting the element string representation: " + e2.getMessage() - + ")/>"; + "< " + (e == null ? "null" : e.getNodeName()) + + "(gquery, error getting the element string representation: " + e2.getMessage() + + ")/>"; } r += (pretty && r.length() > 0 ? "\n " : "") + elStr; } @@ -4557,7 +4544,6 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { return as(Events).trigger(eventbits, keys); } - /** * Trigger a event in all matched elements. * @@ -4598,7 +4584,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { /** * Remove all event delegation that have been bound using - * {@link #delegate(String, int, Function...)} {@link #live(int, Function...)} methods + * {@link #delegate(String, int, Function...)} {@link #live(int, Function...)} methods. + * * @deprecated use {@link #off()} */ public GQuery undelegate() { @@ -4607,7 +4594,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { /** * Undelegate is a way of removing event handlers that have been bound using - * {@link #delegate(String, int, Function...)} method + * {@link #delegate(String, int, Function...)} method. + * * @deprecated use {@link #off(String)} */ public GQuery undelegate(String selector) { @@ -4620,7 +4608,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { /** * Undelegate is a way of removing event handlers that have been bound using - * {@link #delegate(String, int, Function...)} method + * {@link #delegate(String, int, Function...)} method. + * * @deprecated use {@link #off(String)} */ public GQuery undelegate(String selector, int eventBit) { @@ -4633,7 +4622,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { /** * Undelegate is a way of removing event handlers that have been bound using - * {@link #delegate(String, int, Function...)} method + * {@link #delegate(String, int, Function...)} method. + * * @deprecated use {@link #off(String, String)} */ public GQuery undelegate(String selector, String eventName) { @@ -4654,7 +4644,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { /** * This method removes the element's parent. The matched elements replaces their parents within - * the DOM structure. It is the inverse of {@link GQuery#wrap(GQuery)} method + * the DOM structure. It is the inverse of {@link GQuery#wrap(GQuery)} method. * * @return */ @@ -4662,8 +4652,8 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { for (Element parent : parent().elements) { if (!"body".equalsIgnoreCase(parent.getTagName())) { - GQuery $parent = $(parent); - $parent.replaceWith($parent.children()); + GQuery g = $(parent); + g.replaceWith(g.children()); } } return this; @@ -4672,7 +4662,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { /** * Gets the content of the value attribute of the first matched element, returns only the first * value even if it is a multivalued element. To get an array of all values in multivalues - * elements use vals() + * elements use vals(). * * When the first element is a radio-button and is not checked, then it looks for the first * checked radio-button that has the same name in the list of matched elements. @@ -4843,7 +4833,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { } /** - * return the list of attached widgets matching the query + * return the list of attached widgets matching the query. */ public List<Widget> widgets() { List<Widget> widgets = new ArrayList<Widget>(); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/IsProperties.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/IsProperties.java index f630cf21..9a61efe0 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/IsProperties.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/IsProperties.java @@ -17,7 +17,6 @@ package com.google.gwt.query.client; import com.google.gwt.query.client.builders.JsonBuilder; - /** * Interface using for Data Binders valid for JVM and JS. */ @@ -45,12 +44,12 @@ public interface IsProperties { * and a Json implementation in the JVM. */ <T> T getDataImpl(); - + /** * Return the Object with the given key. */ <T> T get(Object key); - + /** * Set an Object with the given key. */ @@ -68,26 +67,26 @@ public interface IsProperties { String toJson(); /** - * return a string which represents the object with an alias for the + * return a string which represents the object with an alias for the * className useful for serialization. * * Example {"user":{"name":"manolo","surname":"carrasco"}} */ String toJsonWithName(); - + /** * return a string which represents the object in a queryString format. */ String toQueryString(); /** - * return the name for this type + * return the name for this type. */ String getJsonName(); - + /** * converts a JsonBuilder instance into another JsonBuilder type but - * preserving the underlying data object. + * preserving the underlying data object. */ - <T extends JsonBuilder> T as (Class<T> clz); + <T extends JsonBuilder> T as(Class<T> clz); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/Lazy.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/Lazy.java index 452688b1..e5395bf4 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/Lazy.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/Lazy.java @@ -21,6 +21,9 @@ package com.google.gwt.query.client; * method calls to the class which implements the Lazy interface. Methods in the * generated class do not execute but instead queue up a deferred execution of * the method. + * + * @param <S> + * @param <T> */ public interface Lazy<S, T extends LazyBase> { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyBase.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyBase.java index c5294aaa..b3dfb55f 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyBase.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyBase.java @@ -18,8 +18,9 @@ package com.google.gwt.query.client; /** * All lazy interfaces must extend this baseclass. This ensures the done() * method exists and returns an executable function. + * + * @param <S> */ public interface LazyBase<S> { - Function done(); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java index 46d9d9ee..df766f9a 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java @@ -12,64 +12,28 @@ * the License. */ package com.google.gwt.query.client; -import static com.google.gwt.query.client.plugins.QueuePlugin.Queue; -import com.google.gwt.core.client.GWT; -import com.google.gwt.core.client.JavaScriptObject; -import com.google.gwt.core.client.JsArray; -import com.google.gwt.core.client.JsArrayMixed; -import com.google.gwt.core.client.JsArrayString; -import com.google.gwt.core.client.ScriptInjector; -import com.google.gwt.dom.client.BodyElement; -import com.google.gwt.dom.client.ButtonElement; -import com.google.gwt.dom.client.Document; + import com.google.gwt.dom.client.Element; -import com.google.gwt.dom.client.InputElement; import com.google.gwt.dom.client.NativeEvent; import com.google.gwt.dom.client.Node; import com.google.gwt.dom.client.NodeList; -import com.google.gwt.dom.client.OptionElement; -import com.google.gwt.dom.client.SelectElement; -import com.google.gwt.dom.client.Style.Display; -import com.google.gwt.dom.client.Style.HasCssName; -import com.google.gwt.dom.client.TextAreaElement; -import com.google.gwt.query.client.css.CSS; +import com.google.gwt.query.client.GQuery.Offset; import com.google.gwt.query.client.css.HasCssValue; import com.google.gwt.query.client.css.TakesCssValue; import com.google.gwt.query.client.css.TakesCssValue.CssSetter; -import com.google.gwt.query.client.impl.AttributeImpl; -import com.google.gwt.query.client.impl.DocumentStyleImpl; -import com.google.gwt.query.client.impl.SelectorEngine; -import com.google.gwt.query.client.js.JsCache; -import com.google.gwt.query.client.js.JsMap; import com.google.gwt.query.client.js.JsNamedArray; import com.google.gwt.query.client.js.JsNodeArray; -import com.google.gwt.query.client.js.JsObjectArray; -import com.google.gwt.query.client.js.JsUtils; import com.google.gwt.query.client.plugins.Effects; -import com.google.gwt.query.client.plugins.Events; -import com.google.gwt.query.client.plugins.Plugin; -import com.google.gwt.query.client.plugins.Widgets; -import com.google.gwt.query.client.plugins.ajax.Ajax; -import com.google.gwt.query.client.plugins.ajax.Ajax.Settings; -import com.google.gwt.query.client.plugins.deferred.Deferred; import com.google.gwt.query.client.plugins.effects.PropertiesAnimation.Easing; -import com.google.gwt.query.client.plugins.events.EventsListener; -import com.google.gwt.query.client.plugins.widgets.WidgetsUtils; -import com.google.gwt.regexp.shared.RegExp; -import com.google.gwt.user.client.DOM; -import com.google.gwt.user.client.Event; -import com.google.gwt.user.client.EventListener; -import com.google.gwt.user.client.Window; -import com.google.gwt.user.client.ui.IsWidget; import com.google.gwt.user.client.ui.Widget; -import java.util.ArrayList; -import java.util.Arrays; + import java.util.List; -import java.util.Map; -import com.google.gwt.query.client.GQuery.*; -import com.google.gwt.query.client.LazyBase; -public interface LazyGQuery<T> extends LazyBase<T>{ +/** + * LazyGQuery. + * @param <T> + */ +public interface LazyGQuery<T> extends LazyBase<T> { /** * Add elements to the set of matched elements if they are not included yet. @@ -127,11 +91,10 @@ public interface LazyGQuery<T> extends LazyBase<T>{ * * NOTE: The ability of animating attribute values is only available in gquery but not jquery * - * * Example: * * <pre class="code"> - * //move the element from its original position to left:500px + * // move the element from its original position to left:500px * $("#foo").animate("left:'500'"); * * // Change the width html attribute of a table, note the symbol '$' to @@ -148,7 +111,7 @@ public interface LazyGQuery<T> extends LazyBase<T>{ * Example: * * <pre class="code"> - * //move the element from its original position to 500px to the left for 500ms and + * // move the element from its original position to 500px to the left for 500ms and * // change the background color of the element at the end of the animation * * $("#foo").animate("left:'+=500'", new Function(){ @@ -186,11 +149,10 @@ public interface LazyGQuery<T> extends LazyBase<T>{ * * NOTE: The ability of animating attribute values is only available in gquery but not jquery * - * * Example: * * <pre class="code"> - * //move the element from its original position to left:500px for 500ms using a swing easing + * // move the element from its original position to left:500px for 500ms using a swing easing * $("#foo").animate("left:'500'", 500, Easing.SWING); * * // Change the width html attribute of a table, note the symbol '$' to @@ -208,8 +170,8 @@ public interface LazyGQuery<T> extends LazyBase<T>{ * Example: * * <pre class="code"> - * //move the element from its original position to 500px to the left and 5OOpx down for 400ms. - * //use a swing easing function for the transition + * // move the element from its original position to 500px to the left and 5OOpx down for 400ms. + * // use a swing easing function for the transition * $("#foo").animate(Properties.create("{top:'+=500px',left:'+=500px'}"), 400, Easing.SWING); * </pre> * @@ -241,11 +203,10 @@ public interface LazyGQuery<T> extends LazyBase<T>{ * * NOTE: The ability of animating attribute values is only available in gquery but not jquery * - * * Example: * * <pre class="code"> - * //move the element from its original position to left:500px for 500ms + * // move the element from its original position to left:500px for 500ms * $("#foo").animate("left:'500'", 500); * * // Change the width html attribute of a table, note the symbol '$' to @@ -263,7 +224,7 @@ public interface LazyGQuery<T> extends LazyBase<T>{ * Example: * * <pre class="code"> - * //move the element from its original position to 500px to the left for 1000ms and + * // move the element from its original position to 500px to the left for 1000ms and * // change the background color of the element at the end of the animation * $("#foo").animate("left:'+=500'", 1000, new Function(){ * public void f(Element e){ @@ -272,7 +233,6 @@ public interface LazyGQuery<T> extends LazyBase<T>{ * }); * </pre> * - * * For color css properties, values can be specified via hexadecimal or rgb or literal values. * * Example: @@ -281,10 +241,8 @@ public interface LazyGQuery<T> extends LazyBase<T>{ * $("#foo").animate("backgroundColor:'red', color:'#ffffff', borderColor:'rgb(129, 0, 70)', 1000"); * </pre> * - * - * @param prop the property to animate : "cssName:'value'" - * @param funcs an array of {@link Function} called once the animation is complete - * @param duration the duration in milliseconds of the animation + * @param stringOrProperties the set of properties to animate : "cssName:'value'" + * @param funcs an array of {@link Function} called once the animation is complete. */ LazyGQuery<T> animate(Object stringOrProperties, int duration, Function... funcs); @@ -398,7 +356,6 @@ public interface LazyGQuery<T> extends LazyBase<T>{ * The event handlers are passed as Functions that you can use to prevent default behavior. To * stop both default action and event bubbling, the function event handler has to return false. * - * */ LazyGQuery<T> bind(int eventbits, Function... funcs); @@ -419,7 +376,6 @@ public interface LazyGQuery<T> extends LazyBase<T>{ * The event handlers are passed as Functions that you can use to prevent default behavior. To * stop both default action and event bubbling, the function event handler has to return false. * - * */ LazyGQuery<T> bind(String eventType, Function... funcs); @@ -528,7 +484,6 @@ public interface LazyGQuery<T> extends LazyBase<T>{ * property defined in {@link CSS} class and call the {@link TakesCssValue#with(HasCssName)} * method on it. * - * * ex : * * <pre class="code"> @@ -902,7 +857,8 @@ public interface LazyGQuery<T> extends LazyBase<T>{ /** * Remove all event handlers previously attached using {@link #live(String, Function)}. In order * for this method to function correctly, the selector used with it must match exactly the - * selector initially used with {@link #live(String, Function)} + * selector initially used with {@link #live(String, Function)}. + * * @deprecated use {@link #off(String, String)} instead */ LazyGQuery<T> die(); @@ -910,7 +866,7 @@ public interface LazyGQuery<T> extends LazyBase<T>{ /** * Remove an event handlers previously attached using {@link #live(int, Function)} In order for * this method to function correctly, the selector used with it must match exactly the selector - * initially used with {@link #live(int, Function)} + * initially used with {@link #live(int, Function)}. * @deprecated use {@link #off(String)} */ LazyGQuery<T> die(int eventbits); @@ -918,7 +874,7 @@ public interface LazyGQuery<T> extends LazyBase<T>{ /** * Remove an event handlers previously attached using {@link #live(String, Function)} In order for * this method to function correctly, the selector used with it must match exactly the selector - * initially used with {@link #live(String, Function)} + * initially used with {@link #live(String, Function)}. */ LazyGQuery<T> die(String eventName); @@ -1250,7 +1206,7 @@ public interface LazyGQuery<T> extends LazyBase<T>{ boolean isEmpty(); /** - * Return true if the first element is visible.isVisible + * Return true if the first element is visible.isVisible. */ boolean isVisible(); @@ -1321,7 +1277,6 @@ public interface LazyGQuery<T> extends LazyBase<T>{ * Attach a handler for this event to all elements which match the current selector, now and in * the future. * <p> - * <p> * Ex : * * <pre> @@ -1374,7 +1329,6 @@ public interface LazyGQuery<T> extends LazyBase<T>{ * Attach a handler for this event to all elements which match the current selector, now and in * the future. The <code>data</code> parameter allows us to pass data to the handler. * <p> - * <p> * Ex : * * <pre> @@ -1580,7 +1534,7 @@ public interface LazyGQuery<T> extends LazyBase<T>{ /** * Get all following siblings of each element up to but not including the element matched by the - * GQuery object, filtered by a selector + * GQuery object, filtered by a selector. * * @return */ @@ -1652,17 +1606,17 @@ public interface LazyGQuery<T> extends LazyBase<T>{ LazyGQuery<T> off(); /** - * Remove an event handler + * Remove an event handler. */ LazyGQuery<T> off(String eventName); /** - * Remove an event handler + * Remove an event handler. */ LazyGQuery<T> off(String eventName, Function f); /** - * Remove an event handler + * Remove an event handler. */ LazyGQuery<T> off(String eventName, String selector); @@ -1733,9 +1687,9 @@ public interface LazyGQuery<T> extends LazyBase<T>{ /** * Get the ancestors of each element in the current set of matched elements, up to but not - * including the element matched by the selector. + * including the node. */ - LazyGQuery<T> parentsUntil(Node selector); + LazyGQuery<T> parentsUntil(Node node); /** * Gets the top and left position of an element relative to its offset parent. The returned object @@ -2162,7 +2116,7 @@ public interface LazyGQuery<T> extends LazyBase<T>{ LazyGQuery<T> setSelector(String selector); /** - * Make all matched elements visible + * Make all matched elements visible. */ LazyGQuery<T> show(); @@ -2360,28 +2314,32 @@ public interface LazyGQuery<T> extends LazyBase<T>{ /** * Remove all event delegation that have been bound using - * {@link #delegate(String, int, Function...)} {@link #live(int, Function...)} methods + * {@link #delegate(String, int, Function...)} {@link #live(int, Function...)} methods. + * * @deprecated use {@link #off()} */ LazyGQuery<T> undelegate(); /** * Undelegate is a way of removing event handlers that have been bound using - * {@link #delegate(String, int, Function...)} method + * {@link #delegate(String, int, Function...)} method. + * * @deprecated use {@link #off(String)} */ LazyGQuery<T> undelegate(String selector); /** * Undelegate is a way of removing event handlers that have been bound using - * {@link #delegate(String, int, Function...)} method + * {@link #delegate(String, int, Function...)} method. + * * @deprecated use {@link #off(String)} */ LazyGQuery<T> undelegate(String selector, int eventBit); /** * Undelegate is a way of removing event handlers that have been bound using - * {@link #delegate(String, int, Function...)} method + * {@link #delegate(String, int, Function...)} method. + * * @deprecated use {@link #off(String, String)} */ LazyGQuery<T> undelegate(String selector, String eventName); @@ -2394,7 +2352,7 @@ public interface LazyGQuery<T> extends LazyBase<T>{ /** * This method removes the element's parent. The matched elements replaces their parents within - * the DOM structure. It is the inverse of {@link GQuery#wrap(GQuery)} method + * the DOM structure. It is the inverse of {@link GQuery#wrap(GQuery)} method. * * @return */ @@ -2403,7 +2361,7 @@ public interface LazyGQuery<T> extends LazyBase<T>{ /** * Gets the content of the value attribute of the first matched element, returns only the first * value even if it is a multivalued element. To get an array of all values in multivalues - * elements use vals() + * elements use vals(). * * When the first element is a radio-button and is not checked, then it looks for the first * checked radio-button that has the same name in the list of matched elements. @@ -2474,7 +2432,7 @@ public interface LazyGQuery<T> extends LazyBase<T>{ <W extends Widget> W widget(int n); /** - * return the list of attached widgets matching the query + * return the list of attached widgets matching the query. */ List<Widget> widgets(); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/Predicate.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/Predicate.java index 262e31fb..55b28e14 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/Predicate.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/Predicate.java @@ -31,13 +31,11 @@ public class Predicate { * @param index * the element position in the gquery elements array. */ - public boolean f(Element e, int index) { - return f((Object)e, index); + public boolean f(Element e, int index) { + return f((Object) e, index); } public <T> boolean f(T e, int index) { return false; } - - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/Promise.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/Promise.java index c35b10f5..3b0650e4 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/Promise.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/Promise.java @@ -13,41 +13,39 @@ */ package com.google.gwt.query.client; -import com.google.gwt.query.client.Function; - /** - * Definition of jquery Promise interface used in gquery. + * Definition of jquery Promise interface used in gquery. */ public interface Promise { - + /** - * Definition of jquery Deferred interface used in gquery. + * Definition of jquery Deferred interface used in gquery. */ public interface Deferred { /** * Call the progressCallbacks on a Deferred object with the given args. */ Deferred notify(Object... o); - + /** * Return a Deferred’s Promise object. */ Promise promise(); - + /** * Reject a Deferred object and call any failCallbacks with the given args. */ Deferred reject(Object... o); - + /** * Resolve a Deferred object and call any doneCallbacks with the given args. */ Deferred resolve(Object... o); } - public static final String PENDING = "pending"; - public static final String REJECTED = "rejected"; - public static final String RESOLVED = "resolved"; + String PENDING = "pending"; + String REJECTED = "rejected"; + String RESOLVED = "resolved"; /** * Add handlers to be called when the Deferred object is either resolved or rejected. @@ -67,7 +65,7 @@ public interface Promise { /** * Utility method to filter and/or chain Deferreds. * - * @deprecated use 'then' instead. + * @deprecated use 'then' instead. * it was deprecated in jquery, and we maintain it here for compatibility. */ @Deprecated @@ -97,15 +95,15 @@ public interface Promise { * @param f a list of 1, 2, or 3 functions, which will be used in this way: * 1st function will be called when the deferred is resolved. * 2nd function that is called when the deferred is rejected. - * 3rd one will be called when progress notifications are sent. + * 3rd one will be called when progress notifications are sent. */ Promise then(Function... f); - + /** * Add filters to be called just in case the Deferred object is rejected returning * a new valid promise so as we can continue the flow control of the chain. * - * It works in the same way than adding a second parameter to {@link then} method but + * It works in the same way than adding a second parameter to {@link then} method but * continuing the flow and making more readable the code. * * Example: @@ -142,7 +140,7 @@ public interface Promise { * Determine whether a Deferred object has been resolved. */ boolean isResolved(); - + /** * Determine whether a Deferred object has been rejected. */ diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java index 2c2ba54c..c9414232 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java @@ -38,7 +38,8 @@ public class Properties extends JavaScriptObject implements IsProperties { return JsUtils.parseJSON(p); } catch (Exception e) { if (!GWT.isProdMode()) { - System.err.println("Error creating Properties: \n> " + properties + "\n< " + p + "\n" + e.getMessage()); + System.err.println("Error creating Properties: \n> " + properties + "\n< " + p + "\n" + + e.getMessage()); } } } @@ -57,10 +58,10 @@ public class Properties extends JavaScriptObject implements IsProperties { public static String wrapPropertiesString(String s) { String ret = s // .replaceAll("\\s*/\\*[\\s\\S]*?\\*/\\s*", "") // Remove comments - .replaceAll("([:\\)\\(,;}{'\"])\\s+" , "$1") // Remove spaces - .replaceAll("\\s+([:\\)\\(,;}{'\"])" , "$1") // Remove spaces + .replaceAll("([:\\)\\(,;}{'\"])\\s+", "$1") // Remove spaces + .replaceAll("\\s+([:\\)\\(,;}{'\"])", "$1") // Remove spaces .replaceFirst("^[\\(]+(.*)[\\)]+$", "$1") // Remove () - .replaceAll("\\([\"']([^\\)]+)[\"']\\)" , "($1)") // Remove quotes + .replaceAll("\\([\"']([^\\)]+)[\"']\\)", "($1)") // Remove quotes .replaceAll("[;,]+([\\w-\\$]+:|$)", ";$1") // Change comma by semicolon .replaceAll("([^,;])([\\]}])", "$1;$2") // Put control semicolon used below .replaceAll(":\\s*[\"']?([^;\\{\\}\\[\\]\"']*)[\"']?\\s*([;,]+|$)", ":\"$1\";") // put quotes to all values (even empty) @@ -71,8 +72,7 @@ public class Properties extends JavaScriptObject implements IsProperties { .replaceAll(";([^:]+):", ",$1:") // change semicolon .replaceAll(";([^:]+):", ",$1:") // change semicolon second pass .replaceAll(":\"(-?\\d[\\d\\.]*|null|false|true)\"[;,]", ":$1,") // numbers do not need quote - .replaceAll("[;,]+([\\]\\}]|$)", "$1") // remove endings - ; + .replaceAll("[;,]+([\\]\\}]|$)", "$1"); // remove endings ret = ret.matches("(^[\\[\\{].*[\\]\\}]$)") ? ret : "{" + ret + "}"; return ret; } @@ -86,7 +86,7 @@ public class Properties extends JavaScriptObject implements IsProperties { } private JsCache c() { - return this.<JsCache>cast(); + return this.<JsCache> cast(); } public final native Properties cloneProps() /*-{ @@ -104,7 +104,7 @@ public class Properties extends JavaScriptObject implements IsProperties { @SuppressWarnings("unchecked") public final <T> T get(Object name) { // Casting because of issue_135 - return (T)c().get(String.valueOf(name)); + return (T) c().get(String.valueOf(name)); } public final boolean getBoolean(Object name) { @@ -119,13 +119,13 @@ public class Properties extends JavaScriptObject implements IsProperties { final Object o = c().get(String.valueOf(name)); if (o != null) { if (o instanceof Function) { - return (Function)o; + return (Function) o; } else if (o instanceof JavaScriptObject) { - Object f = ((JavaScriptObject)o).<Properties>cast().getObject("__f"); + Object f = ((JavaScriptObject) o).<Properties> cast().getObject("__f"); if (f != null && f instanceof Function) { return (Function) f; } - return new JsUtils.JsFunction((JavaScriptObject)o); + return new JsUtils.JsFunction((JavaScriptObject) o); } } return null; @@ -150,7 +150,7 @@ public class Properties extends JavaScriptObject implements IsProperties { @SuppressWarnings("unchecked") public final <T extends JavaScriptObject> T getJavaScriptObject(Object name) { // Casting because of issue_135 - return (T)c().getJavaScriptObject(String.valueOf(name)); + return (T) c().getJavaScriptObject(String.valueOf(name)); } public final JsArrayMixed getArray(Object name) { @@ -207,14 +207,14 @@ public class Properties extends JavaScriptObject implements IsProperties { return JsUtils.param(JsCache.checkNull(this)); } - public final boolean isEmpty(){ + public final boolean isEmpty() { return c().length() == 0; } public final <J extends IsProperties> J load(Object prp) { c().clear(); if (prp instanceof JsCache) { - c().copy((JsCache)prp); + c().copy((JsCache) prp); } return getDataImpl(); } @@ -246,7 +246,7 @@ public class Properties extends JavaScriptObject implements IsProperties { @SuppressWarnings("unchecked") public final <J> J getDataImpl() { - return (J)this; + return (J) this; } public final String getJsonName() { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/Selector.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/Selector.java index fbdcff73..38f51946 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/Selector.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/Selector.java @@ -16,6 +16,7 @@ package com.google.gwt.query.client; import static java.lang.annotation.ElementType.METHOD; + import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/Selectors.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/Selectors.java index 6c44caed..f20619ce 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/Selectors.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/Selectors.java @@ -54,12 +54,12 @@ public interface Selectors { * Set the context for all the selectors. * By default they are evaluated in all the document. */ - public void setRoot(Node node); + void setRoot(Node node); /** * Get the configured root context. */ - public Node getRoot(); + Node getRoot(); /** * Used for benchmarking purposes, it returns true if the selector engine @@ -68,5 +68,5 @@ public interface Selectors { * * It is useful to check if IE8 native selectors are being used. */ - public boolean isDegradated(); + boolean isDegradated(); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilder.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilder.java index b5f30451..41d6cd7e 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilder.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilder.java @@ -17,7 +17,6 @@ package com.google.gwt.query.client.builders; import com.google.gwt.query.client.IsProperties; - /** * Tagging interface used to generate JsonBuilder classes. */ @@ -32,8 +31,9 @@ public interface JsonBuilder extends IsProperties { /** * Returns the wrapped object, normally a Properties jso in client - * but can be used to return the underlying Json implementation in JVM - * @deprecated use asObject() instead + * but can be used to return the underlying Json implementation in JVM. + * + * @deprecated use asObject() instead. */ <J> J getProperties(); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilderBase.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilderBase.java index 57f5a909..a33f676b 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilderBase.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilderBase.java @@ -27,6 +27,11 @@ import com.google.gwt.user.client.Window; import java.util.Arrays; import java.util.List; +/** + * Common class for all JsonBuilder implementations. + * + * @param <J> + */ public abstract class JsonBuilderBase<J extends JsonBuilderBase<?>> implements JsonBuilder { protected Properties p = Properties.create(); @@ -63,19 +68,19 @@ public abstract class JsonBuilderBase<J extends JsonBuilderBase<?>> implements J public J load(Object prp) { assert prp == null || prp instanceof JavaScriptObject || prp instanceof String; if (prp != null && prp instanceof String) { - return parse((String)prp); + return parse((String) prp); } if (prp != null) { - p = (Properties)prp; + p = (Properties) prp; } - return (J)this; + return (J) this; } protected <T> void setArrayBase(String n, T[] r) { if (r.length > 0 && r[0] instanceof JsonBuilder) { JsArray<JavaScriptObject> a = JavaScriptObject.createArray().cast(); for (T o : r) { - a.push(((JsonBuilder)o).<Properties>getDataImpl()); + a.push(((JsonBuilder) o).<Properties> getDataImpl()); } p.set(n, a); } else { @@ -89,12 +94,12 @@ public abstract class JsonBuilderBase<J extends JsonBuilderBase<?>> implements J protected <T> T[] getArrayBase(String n, T[] r, Class<T> clazz) { JsObjectArray<?> a = p.getArray(n).cast(); int l = r.length; - for (int i = 0 ; i < l ; i++) { + for (int i = 0; i < l; i++) { Object w = a.get(i); Class<?> c = w.getClass(); do { if (c.equals(clazz)) { - r[i] = (T)w; + r[i] = (T) w; break; } c = c.getSuperclass(); @@ -147,11 +152,11 @@ public abstract class JsonBuilderBase<J extends JsonBuilderBase<?>> implements J @SuppressWarnings("unchecked") public <T extends IsProperties> T set(Object key, Object val) { if (val instanceof IsProperties) { - p.set(key, ((IsProperties)val).getDataImpl()); + p.set(key, ((IsProperties) val).getDataImpl()); } else { p.set(key, val); } - return (T)this; + return (T) this; } public <T extends JsonBuilder> T as(Class<T> clz) { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonFactory.java index 847fcfbd..4e93b043 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonFactory.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonFactory.java @@ -1,9 +1,29 @@ +/* + * Copyright 2014, The gwtquery team. + * + * 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.gwt.query.client.builders; import com.google.gwt.query.client.IsProperties; +/** + * Factory interface. + */ public interface JsonFactory { <T extends JsonBuilder> T create(Class<T> clz); + IsProperties create(String s); + IsProperties create(); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/Name.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/Name.java index 0c75590d..64f44c59 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/Name.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/Name.java @@ -16,6 +16,7 @@ package com.google.gwt.query.client.builders; import static java.lang.annotation.ElementType.METHOD; + import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/XmlBuilder.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/XmlBuilder.java index 930e7ef9..4d7cba47 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/XmlBuilder.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/XmlBuilder.java @@ -15,10 +15,10 @@ */ package com.google.gwt.query.client.builders; -import java.util.Date; - import com.google.gwt.dom.client.Element; +import java.util.Date; + /** * Tagging interface used to generate XmlBuilder classes. */ @@ -39,32 +39,32 @@ public interface XmlBuilder { Element getRootElement(); /** - * Appends a node + * Appends a node. */ void append(XmlBuilder x); /** - * Appends xml content + * Appends xml content. */ void append(String x); /** - * Returns the text content of the element + * Returns the text content of the element. */ String getText(); /** - * Sets the text content of the element + * Sets the text content of the element. */ <J> J setText(String t); /** - * Returns the text content of the element as a number + * Returns the text content of the element as a number. */ double getTextAsNumber(); /** - * Returns the text content of the element as a date + * Returns the text content of the element as a date. */ Date getTextAsDate(); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/XmlBuilderBase.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/XmlBuilderBase.java index 82bf32bd..91c43874 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/XmlBuilderBase.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/XmlBuilderBase.java @@ -17,8 +17,6 @@ package com.google.gwt.query.client.builders; import static com.google.gwt.query.client.GQuery.$; -import java.util.Date; - import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.core.client.JsDate; import com.google.gwt.dom.client.Element; @@ -26,10 +24,17 @@ import com.google.gwt.query.client.GQuery; import com.google.gwt.query.client.Properties; import com.google.gwt.query.client.js.JsUtils; +import java.util.Date; + +/** + * Common code in XmlBuilder implementations. + * + * @param <J> + */ public abstract class XmlBuilderBase<J extends XmlBuilderBase<?>> implements XmlBuilder { - //TODO empty document - protected GQuery g = $((Element)JsUtils.parseXML("<root/>")); + // TODO empty document + protected GQuery g = $((Element) JsUtils.parseXML("<root/>")); public void append(String xml) { g.append(JsUtils.parseXML(xml)); @@ -74,39 +79,40 @@ public abstract class XmlBuilderBase<J extends XmlBuilderBase<?>> implements Xml } public double getTextAsNumber() { - String t = g.text().replaceAll("[^\\d\\.\\-]", ""); + String t = g.text().replaceAll("[^\\d\\.\\-]", ""); return t.isEmpty() ? 0 : Double.parseDouble(t); } public Date getTextAsDate() { - String t = g.text().trim(); + String t = g.text().trim(); if (t.matches("\\d+")) { return new Date(Long.parseLong(t)); } else { - return new Date((long)JsDate.parse(t)); + return new Date((long) JsDate.parse(t)); } } public boolean getTextAsBoolean() { - String t = g.text().trim().toLowerCase(); + String t = g.text().trim().toLowerCase(); return !t.matches("^(|false|off|0)$"); } public <T extends Enum<T>> T getTextAsEnum(Class<T> clazz) { - String t = g.text().trim(); + String t = g.text().trim(); return Enum.valueOf(clazz, t); } @SuppressWarnings("unchecked") public J load(Object o) { - assert o == null || o instanceof JavaScriptObject && JsUtils.isElement((JavaScriptObject)o) || o instanceof String; + assert o == null || o instanceof JavaScriptObject && JsUtils.isElement((JavaScriptObject) o) + || o instanceof String; if (o != null && o instanceof String) { - return parse((String)o); + return parse((String) o); } if (o != null) { - g=$((Element)o); + g = $((Element) o); } - return (J)this; + return (J) this; } @SuppressWarnings("unchecked") @@ -116,7 +122,7 @@ public abstract class XmlBuilderBase<J extends XmlBuilderBase<?>> implements Xml protected <T> void setArrayBase(String n, T[] r) { String v = ""; - for (T t: r) { + for (T t : r) { v += String.valueOf(t); } setBase(n, v); @@ -129,7 +135,7 @@ public abstract class XmlBuilderBase<J extends XmlBuilderBase<?>> implements Xml @SuppressWarnings("unchecked") public <T> T setText(String t) { g.text(t); - return (T)this; + return (T) this; } public String toString() { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundAttachmentProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundAttachmentProperty.java index 83e48f3b..a3afad98 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundAttachmentProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundAttachmentProperty.java @@ -25,6 +25,9 @@ import com.google.gwt.dom.client.Style.HasCssName; public class BackgroundAttachmentProperty extends CssProperty<BackgroundAttachmentProperty.BackgroundAttachment> { + /** + * BackgroundAttachment. + */ public static enum BackgroundAttachment implements HasCssName { /** * Background image is fixed. @@ -46,7 +49,6 @@ public class BackgroundAttachmentProperty extends }; public abstract String getCssName(); - } private static final String CSS_PROPERTY = "backgroundAttachment"; @@ -60,5 +62,4 @@ public class BackgroundAttachmentProperty extends private BackgroundAttachmentProperty() { super(CSS_PROPERTY); } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundImageProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundImageProperty.java index 126f1491..eb5f10d0 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundImageProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundImageProperty.java @@ -16,7 +16,7 @@ package com.google.gwt.query.client.css; /** - * This property sets the background image of an element, + * This property sets the background image of an element. */ public class BackgroundImageProperty extends CssProperty<UriValue> { @@ -29,5 +29,4 @@ public class BackgroundImageProperty extends CssProperty<UriValue> { private BackgroundImageProperty() { super(CSS_PROPERTY); } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundPositionProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundPositionProperty.java index c0b37fb4..87940bf5 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundPositionProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundPositionProperty.java @@ -27,19 +27,16 @@ public class BackgroundPositionProperty extends /** * Value for <i>background-position</i> property. - * - * @author Julien Dramaix (julien.dramaix@gmail.com) - * */ public static class BackgroundPosition implements HasCssName { /** - * Equivalent to {@link BackgroundPosition#CENTER_BOTTOM} + * Equivalent to {@link BackgroundPosition#CENTER_BOTTOM}. */ public static BackgroundPosition BOTTOM; /** - * Equivalent to {@link BackgroundPosition#CENTER_CENTER} + * Equivalent to {@link BackgroundPosition#CENTER_CENTER}. */ public static BackgroundPosition CENTER; @@ -62,7 +59,7 @@ public class BackgroundPositionProperty extends public static BackgroundPosition CENTER_TOP; /** - * Equivalent to {@link BackgroundPosition#LEFT_CENTER} + * Equivalent to {@link BackgroundPosition#LEFT_CENTER}. */ public static BackgroundPosition LEFT; @@ -85,7 +82,7 @@ public class BackgroundPositionProperty extends public static BackgroundPosition LEFT_TOP; /** - * Equivalent to {@link BackgroundPosition#RIGHT_CENTER} + * Equivalent to {@link BackgroundPosition#RIGHT_CENTER}. */ public static BackgroundPosition RIGHT; @@ -108,7 +105,7 @@ public class BackgroundPositionProperty extends public static BackgroundPosition RIGHT_TOP; /** - * Equivalent to {@link BackgroundPosition#CENTER_TOP} + * Equivalent to {@link BackgroundPosition#CENTER_TOP}. */ public static BackgroundPosition TOP; @@ -134,12 +131,11 @@ public class BackgroundPositionProperty extends RIGHT_TOP = new BackgroundPosition(RIGHT_VALUE + " " + TOP_VALUE); TOP = new BackgroundPosition(TOP_VALUE); BOTTOM = new BackgroundPosition(BOTTOM_VALUE); - } /** * Return a {@link BackgroundPosition} by specifying the horizontal and - * vertical position. Pixel will be used as Unit + * vertical position. Pixel will be used as Unit. */ public static BackgroundPosition position(int xpos, int ypos) { return position(xpos, ypos, Unit.PX); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundRepeatProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundRepeatProperty.java index cfd3e8c8..fb69e7c0 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundRepeatProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundRepeatProperty.java @@ -47,14 +47,13 @@ public class BackgroundRepeatProperty extends */ REPEAT_Y; - public String getCssName(){ + public String getCssName() { return name().toLowerCase().replace('_', '-'); } } private static final String CSS_PROPERTY = "backgroundRepeat"; - public static void init() { CSS.BACKGROUND_REPEAT = new BackgroundRepeatProperty(); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderCollapseProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderCollapseProperty.java index 7a626105..edcfdac4 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderCollapseProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderCollapseProperty.java @@ -23,6 +23,9 @@ import com.google.gwt.dom.client.Style.HasCssName; public class BorderCollapseProperty extends CssProperty<BorderCollapseProperty.BorderCollapse> { + /** + * BorderCollapse. + */ public static enum BorderCollapse implements HasCssName { /** * Borders are collapsed into a single border when possible (border-spacing @@ -45,7 +48,6 @@ public class BorderCollapseProperty extends public static void init() { CSS.BORDER_COLLAPSE = new BorderCollapseProperty(); - } private BorderCollapseProperty() { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderProperty.java index 9ef84d99..c22973f4 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderProperty.java @@ -27,7 +27,6 @@ import com.google.gwt.query.client.css.TakesCssValue.CssSetter; * cannot set different values on the four borders. To do so, one or more of the * other border properties must be used. * - * */ public class BorderProperty implements HasCssValue { @@ -72,5 +71,4 @@ public class BorderProperty implements HasCssValue { RGBColor borderColor) { return new MultipleValueCssSetter(getCssName(), borderWidth, borderStyle, borderColor); } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderSpacingProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderSpacingProperty.java index eee9f71d..81d58fd1 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderSpacingProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderSpacingProperty.java @@ -38,7 +38,7 @@ public class BorderSpacingProperty extends /** * Construct a {@link BorderSpacing} object with same horizontal and - * vertical spacing + * vertical spacing. */ public BorderSpacing(Length spacing) { this(spacing, spacing); @@ -66,7 +66,6 @@ public class BorderSpacingProperty extends public static void init() { CSS.BORDER_SPACING = new BorderSpacingProperty(); - } private BorderSpacingProperty() { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderStyleProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderStyleProperty.java index 714da3f8..d1431407 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderStyleProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderStyleProperty.java @@ -24,6 +24,9 @@ import com.google.gwt.dom.client.Style.HasCssName; public class BorderStyleProperty extends CssProperty<BorderStyleProperty.BorderStyle> { + /** + * BorderStyle. + */ public static enum BorderStyle implements HasCssName { /** * The border is a series of short line segments. @@ -106,5 +109,4 @@ public class BorderStyleProperty extends private BorderStyleProperty(String value) { super(value); } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderWidthProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderWidthProperty.java index a136c5dc..51cb8110 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderWidthProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderWidthProperty.java @@ -43,11 +43,9 @@ public class BorderWidthProperty extends */ THIN; - public String getCssName() { return name().toLowerCase(); } - } private static final String BORDER_BOTTOM_WIDTH_PROPERTY = "borderBottomWidth"; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CSS.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CSS.java index f88e9939..c6a43756 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CSS.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CSS.java @@ -15,37 +15,8 @@ */ package com.google.gwt.query.client.css; -import com.google.gwt.dom.client.Style.Cursor; -import com.google.gwt.dom.client.Style.Display; -import com.google.gwt.dom.client.Style.FontStyle; -import com.google.gwt.dom.client.Style.FontWeight; -import com.google.gwt.dom.client.Style.ListStyleType; -import com.google.gwt.dom.client.Style.Overflow; -import com.google.gwt.dom.client.Style.Position; -import com.google.gwt.dom.client.Style.TextDecoration; -import com.google.gwt.dom.client.Style.VerticalAlign; -import com.google.gwt.dom.client.Style.Visibility; -import com.google.gwt.query.client.css.BackgroundAttachmentProperty.BackgroundAttachment; -import com.google.gwt.query.client.css.BackgroundPositionProperty.BackgroundPosition; -import com.google.gwt.query.client.css.BackgroundRepeatProperty.BackgroundRepeat; -import com.google.gwt.query.client.css.BorderCollapseProperty.BorderCollapse; -import com.google.gwt.query.client.css.BorderSpacingProperty.BorderSpacing; -import com.google.gwt.query.client.css.BorderStyleProperty.BorderStyle; -import com.google.gwt.query.client.css.BorderWidthProperty.BorderWidth; -import com.google.gwt.query.client.css.CaptionSideProperty.CaptionSide; -import com.google.gwt.query.client.css.ClearProperty.Clear; -import com.google.gwt.query.client.css.ClipProperty.Shape; -import com.google.gwt.query.client.css.DirectionProperty.Direction; -import com.google.gwt.query.client.css.EmptyCellsProperty.EmptyCells; -import com.google.gwt.query.client.css.FontSizeProperty.FontSize; -import com.google.gwt.query.client.css.FontVariantProperty.FontVariant; -import com.google.gwt.query.client.css.ListStylePositionProperty.ListStylePosition; import com.google.gwt.query.client.css.MarginProperty.ShorthandMarginProperty; import com.google.gwt.query.client.css.PaddingProperty.ShorthandPaddingProperty; -import com.google.gwt.query.client.css.TextAlignProperty.TextAlign; -import com.google.gwt.query.client.css.TextTransformProperty.TextTransform; -import com.google.gwt.query.client.css.UnicodeBidiProperty.UnicodeBidi; -import com.google.gwt.query.client.css.WhiteSpaceProperty.WhiteSpace; /** * This class lists all CSS properties. @@ -106,7 +77,6 @@ public class CSS { * This property takes a {@link UriValue} object as value. * </p> * - * */ public static BackgroundImageProperty BACKGROUND_IMAGE; @@ -655,7 +625,7 @@ public class CSS { /** * CSS value specifying that the setting of the related property should be - * inherited from the parent element + * inherited from the parent element. */ public static final String INHERIT = "inherit"; @@ -1314,7 +1284,5 @@ public class CSS { WhiteSpaceProperty.init(); WordSpacingProperty.init(); ZIndexProperty.init(); - } - -}
\ No newline at end of file +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CaptionSideProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CaptionSideProperty.java index a1fdce0a..ecb6cc93 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CaptionSideProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CaptionSideProperty.java @@ -63,5 +63,4 @@ public class CaptionSideProperty extends private CaptionSideProperty() { super(CSS_PROPERTY); } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ClearProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ClearProperty.java index 97cfa4f6..a69c3a78 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ClearProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ClearProperty.java @@ -52,7 +52,6 @@ public class ClearProperty extends CssProperty<ClearProperty.Clear> { public String getCssName() { return name().toLowerCase(); } - } private static final String CSS_PROPERTY = "clear"; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ClipProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ClipProperty.java index 83dfb09e..e985ea5c 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ClipProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ClipProperty.java @@ -48,7 +48,6 @@ public class ClipProperty extends CssProperty<ClipProperty.Shape> { public String getCssName() { return value; } - } private static final String CSS_PROPERTY = "clip"; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CssProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CssProperty.java index 59cfc0c3..21b1f4b7 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CssProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CssProperty.java @@ -20,13 +20,16 @@ import com.google.gwt.dom.client.Style; import com.google.gwt.dom.client.Style.HasCssName; /** - * Base class for Css property + * Base class for Css property. * * @param <T> Class of the value associated with the css property */ public class CssProperty<T extends HasCssName> implements TakesCssValue<T> { + /** + * CssSetterImpl. + */ protected class CssSetterImpl implements CssSetter { private T cssValue; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CursorProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CursorProperty.java index ed706423..8cb6ae03 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CursorProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CursorProperty.java @@ -19,7 +19,7 @@ import com.google.gwt.dom.client.Style.Cursor; /** * The <i>cursor</i> property specifies the type of cursor to be displayed for - * the pointing device + * the pointing device. */ public class CursorProperty extends CssProperty<Cursor> { @@ -33,7 +33,7 @@ public class CursorProperty extends CssProperty<Cursor> { super(CSS_PROPERTY); } - public CssSetter with(UriValue url){ + public CssSetter with(UriValue url) { return new SimpleCssSetter(this, url); } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/DirectionProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/DirectionProperty.java index 601ace2a..dd6a5a8f 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/DirectionProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/DirectionProperty.java @@ -46,7 +46,6 @@ public class DirectionProperty extends public String getCssName() { return name().toLowerCase(); } - } private static final String CSS_PROPERTY = "direction"; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/EdgePositionProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/EdgePositionProperty.java index fe6dfd65..c2066bcb 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/EdgePositionProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/EdgePositionProperty.java @@ -15,7 +15,6 @@ */ package com.google.gwt.query.client.css; - /** * Specify position of element's edges. */ @@ -31,5 +30,4 @@ public class EdgePositionProperty extends CssProperty<Length> { private EdgePositionProperty(String value) { super(value); } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/EmptyCellsProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/EmptyCellsProperty.java index e31746a7..55c8926f 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/EmptyCellsProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/EmptyCellsProperty.java @@ -55,5 +55,4 @@ public class EmptyCellsProperty extends private EmptyCellsProperty() { super(CSS_PROPERTY); } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/HasCssValue.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/HasCssValue.java index e219b4d8..f6ea511a 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/HasCssValue.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/HasCssValue.java @@ -19,7 +19,7 @@ import com.google.gwt.dom.client.Style; import com.google.gwt.dom.client.Style.HasCssName; /** - * Minimal contract for an object defining a css property + * Minimal contract for an object defining a css property. * */ public interface HasCssValue extends HasCssName { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/HeightProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/HeightProperty.java index 5ffcced5..e2cd01ff 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/HeightProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/HeightProperty.java @@ -17,7 +17,7 @@ package com.google.gwt.query.client.css; /** * All height css properties : <i>max-height</i>, <i>min-height</i>, - * <i>height</i> + * <i>height</i>. */ public class HeightProperty extends CssProperty<Length> { @@ -34,5 +34,4 @@ public class HeightProperty extends CssProperty<Length> { private HeightProperty(String cssName) { super(cssName); } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/LetterSpacingProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/LetterSpacingProperty.java index a5e7286b..adf0a09c 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/LetterSpacingProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/LetterSpacingProperty.java @@ -30,5 +30,4 @@ public class LetterSpacingProperty extends CssProperty<Length> { private LetterSpacingProperty() { super(CSS_PROPERTY); } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/LineHeightProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/LineHeightProperty.java index 112a1373..70b35cc6 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/LineHeightProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/LineHeightProperty.java @@ -57,5 +57,4 @@ public class LineHeightProperty extends CssProperty<Length> implements public CssSetter with(Double value) { return new SimpleCssSetter(CSS_PROPERTY, value != null ? "" + value : null); } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ListStylePositionProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ListStylePositionProperty.java index 0fcb4c2e..cbac528e 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ListStylePositionProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ListStylePositionProperty.java @@ -45,7 +45,6 @@ public class ListStylePositionProperty extends public String getCssName() { return name().toLowerCase(); } - } private static final String CSS_PROPERTY = "listStylePosition"; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ListStyleProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ListStyleProperty.java index 5eed56a8..4410ff75 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ListStyleProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ListStyleProperty.java @@ -52,5 +52,4 @@ public class ListStyleProperty implements HasCssValue { return new MultipleValueCssSetter(CSS_PROPERTY, listStyleType, listStylePosition, listStyleImage); } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/MarginProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/MarginProperty.java index 00a5b16e..6544508a 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/MarginProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/MarginProperty.java @@ -22,6 +22,9 @@ import com.google.gwt.dom.client.Style; */ public class MarginProperty extends CssProperty<Length> { + /** + * ShorthandMarginProperty. + */ public static class ShorthandMarginProperty implements HasCssValue { private ShorthandMarginProperty() { @@ -36,29 +39,26 @@ public class MarginProperty extends CssProperty<Length> { } /** - * Apply the same margin to all sides + * Apply the same margin to all sides. */ public CssSetter with(Length margin) { return new MultipleValueCssSetter(getCssName(), margin); - } /** * The top and bottom margins are set to the first value and the right and - * left margins are set to the second + * left margins are set to the second. */ public CssSetter with(Length topAndBottom, Length leftAndRight) { return new MultipleValueCssSetter(getCssName(), topAndBottom, leftAndRight); - } /** * The top margin is set to the first value, the left and right margins are - * set to the second, and the bottom margin is set to the third + * set to the second, and the bottom margin is set to the third. */ public CssSetter with(Length top, Length leftAndRight, Length bottom) { return new MultipleValueCssSetter(getCssName(), top, leftAndRight, bottom); - } /** @@ -68,9 +68,7 @@ public class MarginProperty extends CssProperty<Length> { Length margin4) { return new MultipleValueCssSetter(getCssName(), margin1, margin2, margin3, margin4); - } - } private static String MARGIN_BOTTOM_PROPERTY = "marginBottom"; @@ -90,5 +88,4 @@ public class MarginProperty extends CssProperty<Length> { private MarginProperty(String cssName) { super(cssName); } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/MultipleValueCssSetter.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/MultipleValueCssSetter.java index 290d7a65..27dbca04 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/MultipleValueCssSetter.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/MultipleValueCssSetter.java @@ -1,27 +1,42 @@ +/* + * Copyright 2014, The gwtquery team. + * + * 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.gwt.query.client.css; import com.google.gwt.dom.client.Style.HasCssName; +/** + * MultipleValueCssSetter. + */ public class MultipleValueCssSetter extends SimpleCssSetter { - public MultipleValueCssSetter(String cssPropertyName, HasCssName... values) { super(cssPropertyName, computeValue(values)); } - protected static String computeValue(HasCssName... values){ + protected static String computeValue(HasCssName... values) { StringBuilder valueBuilder = new StringBuilder(); - for (HasCssName cssValue : values){ + for (HasCssName cssValue : values) { valueBuilder.append(notNull(cssValue)); } return valueBuilder.toString().trim(); } - private static String notNull(HasCssName value) { return value != null ? value.getCssName() + " " : ""; } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/OutlineColorProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/OutlineColorProperty.java index 713e3d5e..e39dff41 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/OutlineColorProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/OutlineColorProperty.java @@ -28,7 +28,6 @@ public class OutlineColorProperty extends CssProperty<RGBColor> { CSS.OUTLINE_COLOR = new OutlineColorProperty(); } - private OutlineColorProperty() { super(CSS_PROPERTY); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/OutlineProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/OutlineProperty.java index 23405928..820967be 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/OutlineProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/OutlineProperty.java @@ -28,7 +28,7 @@ import com.google.gwt.query.client.css.TakesCssValue.CssSetter; * declaration. */ public class OutlineProperty implements - HasCssValue{ + HasCssValue { private static final String CSS_PROPERTY = "outline"; @@ -59,6 +59,4 @@ public class OutlineProperty implements Length outlineWidth) { return new MultipleValueCssSetter(CSS_PROPERTY, outlineColor, outlineStyle, outlineWidth); } - - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/PaddingProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/PaddingProperty.java index 47474848..43a75f62 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/PaddingProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/PaddingProperty.java @@ -23,6 +23,9 @@ import com.google.gwt.dom.client.Style; */ public class PaddingProperty extends CssProperty<Length> { + /** + * ShorthandPaddingProperty. + */ public static class ShorthandPaddingProperty implements HasCssValue { private ShorthandPaddingProperty() { @@ -37,30 +40,27 @@ public class PaddingProperty extends CssProperty<Length> { } /** - * Apply the same padding to all sides + * Apply the same padding to all sides. */ public CssSetter with(Length padding) { return new MultipleValueCssSetter(getCssName(), padding); - } /** * The top and bottom paddings are set to the first value and the right and - * left paddings are set to the second + * left paddings are set to the second. */ public CssSetter with(Length topAndBottom, Length leftAndRight) { return new MultipleValueCssSetter(getCssName(), topAndBottom, leftAndRight); - } /** * The top padding is set to the first value, the left and right paddings - * are set to the second, and the bottom padding is set to the third + * are set to the second, and the bottom padding is set to the third. */ public CssSetter with(Length top, Length leftAndRight, Length bottom) { return new MultipleValueCssSetter(getCssName(), top, leftAndRight, bottom); - } /** @@ -70,9 +70,7 @@ public class PaddingProperty extends CssProperty<Length> { Length padding4) { return new MultipleValueCssSetter(getCssName(), padding1, padding2, padding3, padding4); - } - } private static String PADDING_BOTTOM_PROPERTY = "paddingBottom"; @@ -92,5 +90,4 @@ public class PaddingProperty extends CssProperty<Length> { private PaddingProperty(String cssName) { super(cssName); } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/PositionProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/PositionProperty.java index c89697c3..e01fc35b 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/PositionProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/PositionProperty.java @@ -32,5 +32,4 @@ public class PositionProperty extends CssProperty<Position> { private PositionProperty() { super(CSS_PROPERTY); } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/SimpleCssSetter.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/SimpleCssSetter.java index 03297f7c..fb605568 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/SimpleCssSetter.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/SimpleCssSetter.java @@ -21,7 +21,7 @@ import com.google.gwt.query.client.css.TakesCssValue.CssSetter; /** * Simple implementation of {@link CssSetter} interface. It does its job for the - * most CSS property + * most CSS property. * */ public class SimpleCssSetter implements CssSetter { @@ -41,7 +41,5 @@ public class SimpleCssSetter implements CssSetter { public void applyCss(Element e) { assert e != null : "Impossible to apply css to a null object"; e.getStyle().setProperty(property, value != null ? value : ""); - } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakesCssValue.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakesCssValue.java index 5f9d922d..def5d1f1 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakesCssValue.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakesCssValue.java @@ -19,13 +19,17 @@ import com.google.gwt.dom.client.Element; /** * An CSS property with values of type T. + * + * @param <T> */ public interface TakesCssValue<T> extends HasCssValue { - public interface CssSetter { - public void applyCss(Element e); + /** + * CssSetter. + */ + interface CssSetter { + void applyCss(Element e); } CssSetter with(T value); - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakesInteger.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakesInteger.java index f298feaa..1ec7fadf 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakesInteger.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakesInteger.java @@ -19,7 +19,7 @@ import com.google.gwt.query.client.css.TakesCssValue.CssSetter; /** * Interface to be implemented by properties which take a integer as defined in - * css2 specification + * css2 specification. * * @see http://www.w3.org/TR/CSS21/syndata.html#value-def-number */ diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakesNumber.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakesNumber.java index fb443198..5fefe271 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakesNumber.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakesNumber.java @@ -19,7 +19,7 @@ import com.google.gwt.query.client.css.TakesCssValue.CssSetter; /** * Interface to be implemented by properties which take a number as defined in - * css2 specification + * css2 specification. * * @see http://www.w3.org/TR/CSS21/syndata.html#value-def-number */ diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TextAlignProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TextAlignProperty.java index bd245ae9..64101e8f 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TextAlignProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TextAlignProperty.java @@ -66,5 +66,4 @@ public class TextAlignProperty extends private TextAlignProperty() { super(CSS_PROPERTY); } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TextDecorationProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TextDecorationProperty.java index e89a9ec8..c6b37f60 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TextDecorationProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TextDecorationProperty.java @@ -41,5 +41,4 @@ public class TextDecorationProperty extends CssProperty<TextDecoration> { private TextDecorationProperty() { super(CSS_PROPERTY); } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TextIdentProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TextIdentProperty.java index b7c1deb7..958932af 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TextIdentProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TextIdentProperty.java @@ -33,5 +33,4 @@ public class TextIdentProperty extends CssProperty<Length> { private TextIdentProperty() { super(CSS_PROPERTY); } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TextTransformProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TextTransformProperty.java index 5d80ca34..c54f9266 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TextTransformProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TextTransformProperty.java @@ -55,5 +55,4 @@ public class TextTransformProperty extends private TextTransformProperty() { super(CSS_PROPERTY); } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/UnicodeBidiProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/UnicodeBidiProperty.java index 9d017cc8..069f00ad 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/UnicodeBidiProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/UnicodeBidiProperty.java @@ -18,13 +18,13 @@ package com.google.gwt.query.client.css; import com.google.gwt.dom.client.Style.HasCssName; /** - * This property defines the text direction/writing direction + * This property defines the text direction/writing direction. */ public class UnicodeBidiProperty extends CssProperty<UnicodeBidiProperty.UnicodeBidi> { /** - * Define possible values for <i>unicode-bidi</i> property + * Define possible values for <i>unicode-bidi</i> property. * */ public static enum UnicodeBidi implements HasCssName { @@ -63,7 +63,6 @@ public class UnicodeBidiProperty extends public String getCssName() { return name().toLowerCase().replace('_', '-'); } - } private static final String CSS_PROPERTY = "unicodeBidi"; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/UriValue.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/UriValue.java index 8059f389..0ea5ca25 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/UriValue.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/UriValue.java @@ -18,12 +18,12 @@ package com.google.gwt.query.client.css; import com.google.gwt.dom.client.Style.HasCssName; /** - * Image as css value + * Image as css value. */ public class UriValue implements HasCssName { /** - * Define an uri by an url + * Define an uri by an url. */ public static UriValue url(String url) { return new UriValue("url('" + url + "')"); @@ -38,5 +38,4 @@ public class UriValue implements HasCssName { public String getCssName() { return value; } - -}
\ No newline at end of file +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/VerticalAlignProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/VerticalAlignProperty.java index 85a60f19..f7aac5d4 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/VerticalAlignProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/VerticalAlignProperty.java @@ -37,5 +37,4 @@ public class VerticalAlignProperty extends CssProperty<VerticalAlign> public CssSetter with(Length value) { return new SimpleCssSetter(this, value); } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/VisibilityProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/VisibilityProperty.java index 8cb4c59e..c54e1c76 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/VisibilityProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/VisibilityProperty.java @@ -33,5 +33,4 @@ public class VisibilityProperty extends CssProperty<Visibility> { private VisibilityProperty() { super(CSS_PROPERTY); } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/WhiteSpaceProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/WhiteSpaceProperty.java index d944f0b9..38ecca52 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/WhiteSpaceProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/WhiteSpaceProperty.java @@ -19,11 +19,14 @@ import com.google.gwt.dom.client.Style.HasCssName; /** * The <i>white-space</i> property declares how white space inside the element - * is handled + * is handled. */ public class WhiteSpaceProperty extends CssProperty<WhiteSpaceProperty.WhiteSpace> { + /** + * WhiteSpace. + */ public enum WhiteSpace implements HasCssName { /** @@ -73,5 +76,4 @@ public class WhiteSpaceProperty extends private WhiteSpaceProperty() { super(CSS_PROPERTY); } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/WidthProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/WidthProperty.java index 865eae3c..b1f7be26 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/WidthProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/WidthProperty.java @@ -16,7 +16,7 @@ package com.google.gwt.query.client.css; /** - * All width css properties : <i>max-width</i>, <i>min-width</i>, <i>width</i> + * All width css properties : <i>max-width</i>, <i>min-width</i>, <i>width</i>. */ public class WidthProperty extends CssProperty<Length> { @@ -33,5 +33,4 @@ public class WidthProperty extends CssProperty<Length> { private WidthProperty(String cssName) { super(cssName); } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/WordSpacingProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/WordSpacingProperty.java index c5552cd3..e62a6aad 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/WordSpacingProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/WordSpacingProperty.java @@ -29,5 +29,4 @@ public class WordSpacingProperty extends CssProperty<Length> { private WordSpacingProperty() { super(CSS_PROPERTY); } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ZIndexProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ZIndexProperty.java index e9da1ba1..2bd55ac9 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ZIndexProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ZIndexProperty.java @@ -38,7 +38,6 @@ public class ZIndexProperty implements TakesInteger { private ZIndexProperty() { } - public String getCssName() { return CSS_PROPERTY; } @@ -53,19 +52,18 @@ public class ZIndexProperty implements TakesInteger { /** * returns a {@link CssSetter} object setting <i>z-index</i> property to the - * specified <code>value</code> + * specified <code>value</code>. */ public CssSetter with(Integer value) { return new SimpleCssSetter(CSS_PROPERTY, value != null ? value.toString() : null); } /** - * See GWT issue 5548 + * See GWT issue 5548. * http://code.google.com/p/google-web-toolkit/issues/detail?id=5548 */ private native String getZIndex(Style s) /*-{ - //force to return a string - return "" + s["zIndex"]; + // force to return a string + return "" + s["zIndex"]; }-*/; - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/AttributeImpl.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/AttributeImpl.java index 0a6a6642..3fc8e3bc 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/AttributeImpl.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/AttributeImpl.java @@ -1,4 +1,5 @@ -/* Copyright 2011, The gwtquery team. +/* + * Copyright 2011, The gwtquery team. * * 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 @@ -10,7 +11,8 @@ * 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. */ + * the License. + */ package com.google.gwt.query.client.impl; import com.google.gwt.dom.client.Element; @@ -28,9 +30,9 @@ public class AttributeImpl { * Interface used for attribute setter implementations. */ public interface AttributeSetter { - public boolean isRemoval(Object value); + boolean isRemoval(Object value); - public void setAttribute(Element e, String name, Object value); + void setAttribute(Element e, String name, Object value); } /** @@ -56,7 +58,7 @@ public class AttributeImpl { } /** - * value must be set on element directly + * value must be set on element directly. */ protected static class ValueAttrSetter extends DefaultSetter { private static AttributeSetter INSTANCE; @@ -75,7 +77,7 @@ public class AttributeImpl { } /** - * Boolean attribute : + * Boolean attribute. * - Ensure to set a boolean value to the element's property with the same * name if this last exists * - Ensure to set an attribute having the value equals to the name (i.e @@ -124,7 +126,7 @@ public class AttributeImpl { /** * For button and inputs, the type cannot be changed once the element is - * attached to the dom ! + * attached to the DOM. */ private static class TypeAttrSetter extends DefaultSetter { private static AttributeSetter INSTANCE; @@ -145,12 +147,12 @@ public class AttributeImpl { String tag = e.getNodeName(); if (NOT_AUTHORIZED_NODE.test(tag) && GQuery.$(e).parents("body").length() > 0) { - //TODO maybe it's better to simply do nothing... + // TODO maybe it's better to simply do nothing... throw new RuntimeException( "You cannot change type of button or input element if the element is already attached to the dom"); } if ("input".equals(tag.toLowerCase()) && "radio".equals(value)) { - //some browser (IE6-9) resets value property of the input when you change the type to radio button + // some browser (IE6-9) resets value property of the input when you change the type to radio button InputElement ie = InputElement.as(e); String keepValue = ie.getValue(); super.setAttribute(ie, "type", value); @@ -190,7 +192,7 @@ public class AttributeImpl { value = fixValue(key, value); for (Element e : gQuery.elements()) { int nodeType = e.getNodeType(); - //don't set attribute on text, comment and attributes nodes + // don't set attribute on text, comment and attributes nodes if (nodeType == 3 || nodeType == 8 || nodeType == 2) { continue; } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/AttributeTridentImpl.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/AttributeTridentImpl.java index 7bb9aeee..f12b65aa 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/AttributeTridentImpl.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/AttributeTridentImpl.java @@ -60,22 +60,22 @@ public class AttributeTridentImpl extends AttributeImpl { } } - private static native String getAttributeNode(Element e, String name)/*-{ - var attrNode = e.getAttributeNode(name); - if (attrNode && attrNode.nodeValue !== "") { - return attrNode.nodeValue; - } - return null; + private static native String getAttributeNode(Element e, String name) /*-{ + var attrNode = e.getAttributeNode(name); + if (attrNode && attrNode.nodeValue !== "") { + return attrNode.nodeValue; + } + return null; }-*/; private static native boolean setAttributeNode(Element e, String name, - Object value)/*-{ - var attrNode = e.getAttributeNode(name); - if (attrNode) { - attrNode.nodeValue = value; - return true; - } - return false; + Object value) /*-{ + var attrNode = e.getAttributeNode(name); + if (attrNode) { + attrNode.nodeValue = value; + return true; + } + return false; }-*/; @Override diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/ConsoleBrowser.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/ConsoleBrowser.java index 0c3b1090..22407506 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/ConsoleBrowser.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/ConsoleBrowser.java @@ -27,11 +27,11 @@ import com.google.gwt.query.client.js.JsObjectArray; public class ConsoleBrowser implements Console { /** - * http://whattheheadsaid.com/2011/04/internet-explorer-9s-problematic-console-object + * http://whattheheadsaid.com/2011/04/internet-explorer-9s-problematic-console-object. */ private static class ConsoleIe8 extends ConsoleIe9 { @Override - protected native void init()/*-{ + protected native void init() /*-{ try { Function.prototype.call.call($wnd.console.log, $wnd.console, Array.prototype.slice.call(arguments)); this.@com.google.gwt.query.client.impl.ConsoleBrowser.ConsoleIe9::initialized = true; @@ -41,22 +41,22 @@ public class ConsoleBrowser implements Console { } /** - * See: http://whattheheadsaid.com/2011/04/internet-explorer-9s-problematic-console-object + * See: http://whattheheadsaid.com/2011/04/internet-explorer-9s-problematic-console-object. */ private static class ConsoleIe9 extends ConsoleImpl { private boolean initialized = false; - public ConsoleIe9(){ + public ConsoleIe9() { init(); } - protected native void init()/*-{ + protected native void init() /*-{ try { - [ "log", "info", "warn", "error", "dir", "clear", "profile", "profileEnd" ] - .forEach(function(method) { - $wnd.console[method] = this.call($wnd.console[method], $wnd.console); - }, Function.prototype.bind); + [ "log", "info", "warn", "error", "dir", "clear", "profile", "profileEnd" ] + .forEach(function(method) { + $wnd.console[method] = this.call($wnd.console[method], $wnd.console); + }, Function.prototype.bind); this.@com.google.gwt.query.client.impl.ConsoleBrowser.ConsoleIe9::initialized = true; } catch(e) { } @@ -64,48 +64,80 @@ public class ConsoleBrowser implements Console { @Override public void clear() { - if (initialized) super.clear(); + if (initialized) { + super.clear(); + } } + @Override public void dir(Object arg) { - if (initialized) super.dir(arg); + if (initialized) { + super.dir(arg); + } } + @Override public void error(JavaScriptObject arg) { - if (initialized) super.error(arg); + if (initialized) { + super.error(arg); + } } + @Override public void info(JavaScriptObject arg) { - if (initialized) super.info(arg); + if (initialized) { + super.info(arg); + } } + @Override public void profile(String title) { - if (initialized) super.profile(title); + if (initialized) { + super.profile(title); + } } + @Override public void profileEnd(String title) { - if (initialized) super.profileEnd(title); + if (initialized) { + super.profileEnd(title); + } } + @Override public void warn(JavaScriptObject arg) { - if (initialized) super.warn(arg); + if (initialized) { + super.warn(arg); + } } + @Override - public void group(Object arg) {} + public void group(Object arg) { + } + @Override - public void groupCollapsed(Object arg) {} + public void groupCollapsed(Object arg) { + } + @Override - public void groupEnd() {} + public void groupEnd() { + } + @Override - public void time(String title) {} + public void time(String title) { + } + @Override - public void timeStamp(Object arg) {} + public void timeStamp(Object arg) { + } + @Override - public void timeEnd(String title) {} + public void timeEnd(String title) { + } } /** - * Default implementation: webkit, opera, FF, ie10 + * Default implementation: webkit, opera, FF, IE10. */ private static class ConsoleImpl { public native void clear() /*-{ @@ -168,7 +200,9 @@ public class ConsoleBrowser implements Console { private ConsoleImpl impl; public ConsoleBrowser() { - impl = GQuery.browser.ie8? new ConsoleIe8(): GQuery.browser.ie9? new ConsoleIe9(): new ConsoleImpl(); + impl = + GQuery.browser.ie8 ? new ConsoleIe8() : GQuery.browser.ie9 ? new ConsoleIe9() + : new ConsoleImpl(); } @Override diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java index 24008e1b..d7b83337 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java @@ -31,10 +31,10 @@ import com.google.gwt.user.client.DOM; */ public class DocumentStyleImpl { - private static final RegExp cssNumberRegex = RegExp.compile("^(fillOpacity|fontWeight|lineHeight|opacity|orphans|widows|zIndex|zoom)$", "i"); + private static final RegExp cssNumberRegex = RegExp.compile( + "^(fillOpacity|fontWeight|lineHeight|opacity|orphans|widows|zIndex|zoom)$", "i"); private static final RegExp sizeRegex = RegExp.compile("^(client|offset|)(width|height)$", "i"); - /** * Returns the numeric value of a css property. * @@ -93,15 +93,15 @@ public class DocumentStyleImpl { return ""; } name = fixPropertyName(name); - //value defined in the element style + // value defined in the element style String ret = elem.getStyle().getProperty(name); if (force) { Element toDetach = null; if (JsUtils.isDetached(elem)) { - // If the element is detached to the DOM we attach temporary to it - toDetach = attachTemporary(elem); + // If the element is detached to the DOM we attach temporary to it + toDetach = attachTemporary(elem); } if (sizeRegex.test(name)) { @@ -114,7 +114,7 @@ public class DocumentStyleImpl { // If the element was previously attached, detached it. if (toDetach != null) { - toDetach.removeFromParent(); + toDetach.removeFromParent(); } } @@ -122,17 +122,17 @@ public class DocumentStyleImpl { } private Element attachTemporary(Element elem) { - Element lastParent = $(elem).parents().last().get(0); + Element lastParent = $(elem).parents().last().get(0); - if (lastParent == null){ - //the element itself is detached - lastParent = elem; - } + if (lastParent == null) { + // the element itself is detached + lastParent = elem; + } - Document.get().getBody().appendChild(lastParent); + Document.get().getBody().appendChild(lastParent); - return lastParent; -} + return lastParent; + } /** * Fix style property names. @@ -168,7 +168,8 @@ public class DocumentStyleImpl { // inline elements do not have width nor height unless we set it to inline-block private void fixInlineElement(Element e) { - if (e.getClientHeight() == 0 && e.getClientWidth() == 0 && "inline".equals(curCSS(e, "display", true))) { + if (e.getClientHeight() == 0 && e.getClientWidth() == 0 + && "inline".equals(curCSS(e, "display", true))) { setStyleProperty(e, "display", "inline-block"); setStyleProperty(e, "width", "auto"); setStyleProperty(e, "height", "auto"); @@ -195,7 +196,8 @@ public class DocumentStyleImpl { public int getHeight(Element e) { fixInlineElement(e); - return (int) (e.getClientHeight() - num(curCSS(e, "paddingTop", true)) - num(curCSS(e, "paddingBottom", true))); + return (int) (e.getClientHeight() - num(curCSS(e, "paddingTop", true)) - num(curCSS(e, + "paddingBottom", true))); } public double getOpacity(Element e) { @@ -205,7 +207,8 @@ public class DocumentStyleImpl { public int getWidth(Element e) { fixInlineElement(e); - return (int) (e.getClientWidth() - num(curCSS(e, "paddingLeft", true)) - num(curCSS(e, "paddingRight", true))); + return (int) (e.getClientWidth() - num(curCSS(e, "paddingLeft", true)) - num(curCSS(e, + "paddingRight", true))); } /** @@ -254,8 +257,8 @@ public class DocumentStyleImpl { protected native String getComputedStyle(Element elem, String hyphenName, String camelName, String pseudo) /*-{ try { - var cStyle = $doc.defaultView.getComputedStyle(elem, pseudo); - return cStyle && cStyle.getPropertyValue ? cStyle.getPropertyValue(hyphenName) : null; + var cStyle = $doc.defaultView.getComputedStyle(elem, pseudo); + return cStyle && cStyle.getPropertyValue ? cStyle.getPropertyValue(hyphenName) : null; } catch(e) {return null;} }-*/; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImplIE.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImplIE.java index cb0e097c..972e4645 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImplIE.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImplIE.java @@ -39,7 +39,8 @@ public class DocumentStyleImplIE extends DocumentStyleImpl { @Override public int getHeight(Element e) { - return (int) (e.getOffsetHeight() - num(curCSS(e, "paddingTop", true)) - num(curCSS(e, "paddingBottom", true)) + return (int) (e.getOffsetHeight() - num(curCSS(e, "paddingTop", true)) + - num(curCSS(e, "paddingBottom", true)) - num(curCSS(e, "borderTopWidth", true)) - num(curCSS(e, "borderBottomWidth", true))); } @@ -55,7 +56,8 @@ public class DocumentStyleImplIE extends DocumentStyleImpl { @Override public int getWidth(Element e) { - return (int) (e.getOffsetWidth() - num(curCSS(e, "paddingLeft", true)) - num(curCSS(e, "paddingRight", true)) + return (int) (e.getOffsetWidth() - num(curCSS(e, "paddingLeft", true)) + - num(curCSS(e, "paddingRight", true)) - num(curCSS(e, "borderRightWidth", true)) - num(curCSS(e, "borderRightWidth", true))); } @@ -67,7 +69,6 @@ public class DocumentStyleImplIE extends DocumentStyleImpl { e.style.removeAttribute(prop); }-*/; - /** * Set the value of a style property of an element. * IE needs a special workaround to handle opacity @@ -110,4 +111,4 @@ public class DocumentStyleImplIE extends DocumentStyleImpl { e.getStyle().setProperty("filter", "alpha(opacity=" + (int) (Double.valueOf(val) * 100) + ")"); } -}
\ No newline at end of file +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/HasSelector.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/HasSelector.java index 8ca0a3b7..9e80cae2 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/HasSelector.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/HasSelector.java @@ -19,6 +19,9 @@ import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Node; import com.google.gwt.dom.client.NodeList; +/** + * + */ public interface HasSelector { /** @@ -29,5 +32,4 @@ public interface HasSelector { * @return a list of matched nodes */ NodeList<Element> select(String selector, Node ctx); - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngine.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngine.java index 967961e8..c9bdef5a 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngine.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngine.java @@ -15,16 +15,14 @@ */ package com.google.gwt.query.client.impl; -import static com.google.gwt.query.client.GQuery.*; - -import java.util.HashSet; +import static com.google.gwt.query.client.GQuery.document; +import static com.google.gwt.query.client.GQuery.window; import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Node; import com.google.gwt.dom.client.NodeList; -import com.google.gwt.query.client.GQuery; import com.google.gwt.query.client.Predicate; import com.google.gwt.query.client.js.JsMap; import com.google.gwt.query.client.js.JsNodeArray; @@ -32,6 +30,8 @@ import com.google.gwt.query.client.js.JsUtils; import com.google.gwt.regexp.shared.MatchResult; import com.google.gwt.regexp.shared.RegExp; +import java.util.HashSet; + /** * Core Selector engine functions, and native JS utility functions. */ @@ -41,15 +41,15 @@ public class SelectorEngine implements HasSelector { public static native NodeList<Element> getElementsByClassName(String clazz, Node ctx) /*-{ - return ctx.getElementsByClassName(clazz); + return ctx.getElementsByClassName(clazz); }-*/; public static native Node getNextSibling(Node n) /*-{ - return n.nextSibling || null; + return n.nextSibling || null; }-*/; public static native Node getPreviousSibling(Node n) /*-{ - return n.previousSibling || null; + return n.previousSibling || null; }-*/; public NodeList<Element> querySelectorAll(String selector, Node ctx) { @@ -65,17 +65,17 @@ public class SelectorEngine implements HasSelector { public static native NodeList<Element> querySelectorAllImpl(String selector, Node ctx) /*-{ - return ctx.querySelectorAll(selector); + return ctx.querySelectorAll(selector); }-*/; public static native NodeList<Element> elementsByTagName(String selector, Node ctx) /*-{ - return ctx.getElementsByTagName(selector); + return ctx.getElementsByTagName(selector); }-*/; public static native NodeList<Element> elementsByClassName(String selector, Node ctx) /*-{ - return ctx.getElementsByClassName(selector); + return ctx.getElementsByClassName(selector); }-*/; public static NodeList<Element> veryQuickId(String id, Node ctx) { @@ -90,14 +90,14 @@ public class SelectorEngine implements HasSelector { public static native NodeList<Element> xpathEvaluate(String selector, Node ctx, JsNodeArray r) /*-{ - var node; - var ownerDoc = ctx && (ctx.ownerDocument || ctx ); - var evalDoc = ownerDoc ? ownerDoc : $doc; - var result = evalDoc.evaluate(selector, ctx, null, 0, null); - while ((node = result.iterateNext())) { - r.push(node); - } - return r; + var node; + var ownerDoc = ctx && (ctx.ownerDocument || ctx ); + var evalDoc = ownerDoc ? ownerDoc : $doc; + var result = evalDoc.evaluate(selector, ctx, null, 0, null); + while ((node = result.iterateNext())) { + r.push(node); + } + return r; }-*/; public final SelectorEngineImpl impl; @@ -117,10 +117,10 @@ public class SelectorEngine implements HasSelector { static { filters = JsMap.create(); - filters.put("visible", new Predicate(){ + filters.put("visible", new Predicate() { public boolean f(Element e, int index) { return (e.getOffsetWidth() + e.getOffsetHeight()) > 0 && - !"none".equalsIgnoreCase(styleImpl.curCSS(e, "display", true)); + !"none".equalsIgnoreCase(styleImpl.curCSS(e, "display", true)); } }); filters.put("hidden", new Predicate() { @@ -133,12 +133,12 @@ public class SelectorEngine implements HasSelector { return e.getPropertyBoolean("selected"); } }); - filters.put("input", new Predicate(){ + filters.put("input", new Predicate() { public boolean f(Element e, int index) { return e.getNodeName().toLowerCase().matches("input|select|textarea|button"); } }); - filters.put("header", new Predicate(){ + filters.put("header", new Predicate() { public boolean f(Element e, int index) { return e.getNodeName().toLowerCase().matches("h\\d"); } @@ -173,7 +173,7 @@ public class SelectorEngine implements HasSelector { public NodeList<Element> filter(NodeList<Element> nodes, String selector, boolean filterDetached) { JsNodeArray res = JsNodeArray.create(); - if (selector.isEmpty()){ + if (selector.isEmpty()) { return res; } Element ghostParent = null; @@ -181,7 +181,8 @@ public class SelectorEngine implements HasSelector { HashSet<Node> elmList = new HashSet<Node>(); for (int i = 0, l = nodes.getLength(); i < l; i++) { Node e = nodes.getItem(i); - if (e == window || e == document || e.getNodeName() == null || "html".equalsIgnoreCase(e.getNodeName())) { + if (e == window || e == document || e.getNodeName() == null + || "html".equalsIgnoreCase(e.getNodeName())) { continue; } elmList.add(e); @@ -198,11 +199,11 @@ public class SelectorEngine implements HasSelector { parents.add(p); } } else if (parents.isEmpty()) { - parents.add(document); + parents.add(document); } } for (Node e : parents) { - NodeList<Element> n = select(selector, e); + NodeList<Element> n = select(selector, e); for (int i = 0, l = n.getLength(); i < l; i++) { Element el = n.getItem(i); if (elmList.remove(el)) { @@ -217,9 +218,12 @@ public class SelectorEngine implements HasSelector { } // pseudo selectors which are computed by gquery in runtime - RegExp gQueryPseudo = RegExp.compile("(.*):((visible|hidden|selected|input|header)|((button|checkbox|file|hidden|image|password|radio|reset|submit|text)\\s*(,|$)))(.*)", "i"); + RegExp gQueryPseudo = + RegExp.compile( + "(.*):((visible|hidden|selected|input|header)|((button|checkbox|file|hidden|image|password|radio|reset|submit|text)\\s*(,|$)))(.*)", "i"); // pseudo selectors which work in engine - RegExp nativePseudo = RegExp.compile("(.*):([\\w]+):(disabled|checked|enabled|empty|focus)\\s*([:,].*|$)", "i"); + RegExp nativePseudo = RegExp.compile( + "(.*):([\\w]+):(disabled|checked|enabled|empty|focus)\\s*([:,].*|$)", "i"); public NodeList<Element> select(String selector, Node ctx) { @@ -247,7 +251,7 @@ public class SelectorEngine implements HasSelector { if (pred != null) { nodes = filter(select(select, ctx), pred); } else if (nativePseudo.test(pseudo)) { - nodes = select(select, ctx); + nodes = select(select, ctx); } else { nodes = select(select + "[type=" + pseudo + "]", ctx); } @@ -280,7 +284,7 @@ public class SelectorEngine implements HasSelector { } /** - * Check if the browser has native support for css selectors + * Check if the browser has native support for css selectors. */ public static native boolean hasQuerySelectorAll() /*-{ return $doc.location.href.indexOf("_force_no_native") < 0 && diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineCssToXPath.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineCssToXPath.java index cbee96f1..7a634c83 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineCssToXPath.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineCssToXPath.java @@ -17,8 +17,6 @@ package com.google.gwt.query.client.impl; import static com.google.gwt.query.client.GQuery.console; -import java.util.ArrayList; - import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.JsArray; import com.google.gwt.dom.client.Element; @@ -30,6 +28,8 @@ import com.google.gwt.query.client.js.JsUtils; import com.google.gwt.regexp.shared.MatchResult; import com.google.gwt.regexp.shared.RegExp; +import java.util.ArrayList; + /** * Runtime selector engine implementation which translates selectors to XPath * and delegates to document.evaluate(). @@ -42,14 +42,14 @@ public class SelectorEngineCssToXPath extends SelectorEngineImpl { /** * Interface for callbacks in replaceAll operations. */ - public static interface ReplaceCallback { + public interface ReplaceCallback { String foundMatch(ArrayList<String> s); } /** * Interface for replacer implementations (GWT and JVM). */ - public static interface Replacer { + public interface Replacer { String replaceAll(String s, String expr, Object replacement); } @@ -58,20 +58,22 @@ public class SelectorEngineCssToXPath extends SelectorEngineImpl { private static ReplaceCallback rc_scp = new ReplaceCallback() { public String foundMatch(ArrayList<String> s) { return s.get(1) + s.get(2) + - (s.get(3).startsWith(" ") ? "%S%" : s.get(3).startsWith("#") ? "%H%" : "%P%") + - s.get(4) + s.get(5); + (s.get(3).startsWith(" ") ? "%S%" : s.get(3).startsWith("#") ? "%H%" : "%P%") + + s.get(4) + s.get(5); } }; private static ReplaceCallback rc_$Attr = new ReplaceCallback() { public String foundMatch(ArrayList<String> s) { - return "[substring(@" + s.get(1) + ",string-length(@" + s.get(1) + ")-" + (s.get(2).replaceAll("'", "").length() - 1) + ")=" + s.get(2) + "]"; + return "[substring(@" + s.get(1) + ",string-length(@" + s.get(1) + ")-" + + (s.get(2).replaceAll("'", "").length() - 1) + ")=" + s.get(2) + "]"; } }; private static ReplaceCallback rc_Not = new ReplaceCallback() { public String foundMatch(ArrayList<String> s) { - return s.get(1) + "[not(" + getInstance().css2Xpath(s.get(2)).replaceAll("^[^\\[]+\\[([^\\]]*)\\].*$", "$1" + ")]"); + return s.get(1) + "[not(" + + getInstance().css2Xpath(s.get(2)).replaceAll("^[^\\[]+\\[([^\\]]*)\\].*$", "$1" + ")]"); } }; @@ -82,7 +84,7 @@ public class SelectorEngineCssToXPath extends SelectorEngineImpl { boolean afterAttr = "]".equals(s1); String prefix = afterAttr ? s1 : "*"; - boolean noPrefix = afterAttr || s1 == null || s1.length() == 0 ; + boolean noPrefix = afterAttr || s1 == null || s1.length() == 0; if ("n".equals(s2)) { return s1; @@ -91,89 +93,91 @@ public class SelectorEngineCssToXPath extends SelectorEngineImpl { return prefix + "[position() mod 2=0 and position()>=0]" + (noPrefix ? "" : "/self::" + s1); } if ("odd".equals(s2)) { - prefix = afterAttr ? prefix : noPrefix ? "" : s1; + prefix = afterAttr ? prefix : noPrefix ? "" : s1; return prefix + "[(count(preceding-sibling::*) + 1) mod 2=1]"; } - if (!s2.contains("n")){ - return prefix + "[position() = "+s2+"]" + (noPrefix ? "" : "/self::" + s1); + if (!s2.contains("n")) { + return prefix + "[position() = " + s2 + "]" + (noPrefix ? "" : "/self::" + s1); } String[] t = s2.replaceAll("^([0-9]*)n.*?([0-9]*)?$", "$1+$2").split("\\+"); String t0 = t[0]; String t1 = t.length > 1 ? t[1] : "0"; - return prefix + "[(position()-" + t1 + ") mod " + t0 + "=0 and position()>=" + t1 + "]" + (noPrefix ? "" : "/self::" + s1); + return prefix + "[(position()-" + t1 + ") mod " + t0 + "=0 and position()>=" + t1 + "]" + + (noPrefix ? "" : "/self::" + s1); } }; - public static Object[] regs = new Object[]{ - // scape some dots and spaces - "(['\\[])([^'\\]]*)([\\s\\.#])([^'\\]]*)(['\\]])", rc_scp, - // add @ for attrib - "\\[([^@\\]~\\$\\*\\^\\|\\!]+)(=[^\\]]+)?\\]", "[@$1$2]", - // multiple queries - "\\s*,\\s*", "|.//", - // , + ~ > - "\\s*(\\+|~|>)\\s*", "$1", - //* ~ + > - "([\\w\\-\\*])~([\\w\\-\\*])", "$1/following-sibling::$2", - "([\\w\\-\\*])\\+([\\w\\-\\*])", "$1/following-sibling::*[1]/self::$2", - "([\\w\\-\\*])>([\\w\\-\\*])", "$1/$2", - // all unescaped stuff escaped - "\\[([^=]+)=([^'|\"][^\\]]*)\\]", "[$1='$2']", - // all descendant or self to - "(^|[^\\w\\-\\*])(#|\\.)([\\w\\-]+)", "$1*$2$3", - "([\\>\\+\\|\\~\\,\\s])([a-zA-Z\\*]+)", "$1//$2", - "\\s+//", "//", - // :first-child - "([\\w\\-\\*]+):first-child", "*[1]/self::$1", - // :last-child - "([\\w\\-\\*]+):last-child", "$1[not(following-sibling::*)]", - // :only-child - "([\\w\\-\\*]+):only-child", "*[last()=1]/self::$1", - // :empty - "([\\w\\-\\*]+):empty", "$1[not(*) and not(normalize-space())]", - // :odd :even, this is intentional since sizzle behaves so - ":odd" , ":nth-child(even)", - ":even" , ":nth-child(odd)", - // :not - "(.+):not\\(([^\\)]*)\\)", rc_Not, - // :nth-child - "([a-zA-Z0-9\\_\\-\\*]*|\\]):nth-child\\(([^\\)]*)\\)", rc_nth_child, - // :contains(selectors) - ":contains\\(([^\\)]*)\\)", "[contains(string(.),'$1')]", - // |= attrib - "\\[([\\w\\-]+)\\|=([^\\]]+)\\]", "[@$1=$2 or starts-with(@$1,concat($2,'-'))]", - // *= attrib - "\\[([\\w\\-]+)\\*=([^\\]]+)\\]", "[contains(@$1,$2)]", - // ~= attrib - "\\[([\\w\\-]+)~=([^\\]]+)\\]", "[contains(concat(' ',normalize-space(@$1),' '),concat(' ',$2,' '))]", - // ^= attrib - "\\[([\\w\\-]+)\\^=([^\\]]+)\\]", "[starts-with(@$1,$2)]", - // $= attrib - "\\[([\\w\\-]+)\\$=([^\\]]+)\\]", rc_$Attr, - // != attrib - "\\[([\\w\\-]+)\\!=([^\\]]+)\\]", "[not(@$1) or @$1!=$2]", - // ids and classes - "#([\\w\\-]+)", "[@id='$1']", - "\\.([\\w\\-]+)", "[contains(concat(' ',normalize-space(@class),' '),' $1 ')]", - // normalize multiple filters - "\\]\\[([^\\]]+)", " and ($1)", - // tag:pseudo - ":(enabled)", "[not(@disabled)]", - ":(checked)", "[@$1='$1']", - ":(disabled)", "[@$1]", - ":(first)", "[1]", - ":(last)", "[last()]", - // put '*' when tag is omitted - "(^|\\|[\\./]*)(\\[)", "$1*$2", - // Replace escaped dots and spaces - "%S%"," ", - "%P%",".", - "%H%","#", - // Duplicated quotes - "'+","'", - }; + public static Object[] regs = new Object[] { + // scape some dots and spaces + "(['\\[])([^'\\]]*)([\\s\\.#])([^'\\]]*)(['\\]])", rc_scp, + // add @ for attrib + "\\[([^@\\]~\\$\\*\\^\\|\\!]+)(=[^\\]]+)?\\]", "[@$1$2]", + // multiple queries + "\\s*,\\s*", "|.//", + // , + ~ > + "\\s*(\\+|~|>)\\s*", "$1", + // * ~ + > + "([\\w\\-\\*])~([\\w\\-\\*])", "$1/following-sibling::$2", + "([\\w\\-\\*])\\+([\\w\\-\\*])", "$1/following-sibling::*[1]/self::$2", + "([\\w\\-\\*])>([\\w\\-\\*])", "$1/$2", + // all unescaped stuff escaped + "\\[([^=]+)=([^'|\"][^\\]]*)\\]", "[$1='$2']", + // all descendant or self to + "(^|[^\\w\\-\\*])(#|\\.)([\\w\\-]+)", "$1*$2$3", + "([\\>\\+\\|\\~\\,\\s])([a-zA-Z\\*]+)", "$1//$2", + "\\s+//", "//", + // :first-child + "([\\w\\-\\*]+):first-child", "*[1]/self::$1", + // :last-child + "([\\w\\-\\*]+):last-child", "$1[not(following-sibling::*)]", + // :only-child + "([\\w\\-\\*]+):only-child", "*[last()=1]/self::$1", + // :empty + "([\\w\\-\\*]+):empty", "$1[not(*) and not(normalize-space())]", + // :odd :even, this is intentional since sizzle behaves so + ":odd", ":nth-child(even)", + ":even", ":nth-child(odd)", + // :not + "(.+):not\\(([^\\)]*)\\)", rc_Not, + // :nth-child + "([a-zA-Z0-9\\_\\-\\*]*|\\]):nth-child\\(([^\\)]*)\\)", rc_nth_child, + // :contains(selectors) + ":contains\\(([^\\)]*)\\)", "[contains(string(.),'$1')]", + // |= attrib + "\\[([\\w\\-]+)\\|=([^\\]]+)\\]", "[@$1=$2 or starts-with(@$1,concat($2,'-'))]", + // *= attrib + "\\[([\\w\\-]+)\\*=([^\\]]+)\\]", "[contains(@$1,$2)]", + // ~= attrib + "\\[([\\w\\-]+)~=([^\\]]+)\\]", + "[contains(concat(' ',normalize-space(@$1),' '),concat(' ',$2,' '))]", + // ^= attrib + "\\[([\\w\\-]+)\\^=([^\\]]+)\\]", "[starts-with(@$1,$2)]", + // $= attrib + "\\[([\\w\\-]+)\\$=([^\\]]+)\\]", rc_$Attr, + // != attrib + "\\[([\\w\\-]+)\\!=([^\\]]+)\\]", "[not(@$1) or @$1!=$2]", + // ids and classes + "#([\\w\\-]+)", "[@id='$1']", + "\\.([\\w\\-]+)", "[contains(concat(' ',normalize-space(@class),' '),' $1 ')]", + // normalize multiple filters + "\\]\\[([^\\]]+)", " and ($1)", + // tag:pseudo + ":(enabled)", "[not(@disabled)]", + ":(checked)", "[@$1='$1']", + ":(disabled)", "[@$1]", + ":(first)", "[1]", + ":(last)", "[last()]", + // put '*' when tag is omitted + "(^|\\|[\\./]*)(\\[)", "$1*$2", + // Replace escaped dots and spaces + "%S%", " ", + "%P%", ".", + "%H%", "#", + // Duplicated quotes + "'+", "'", + }; public static SelectorEngineCssToXPath getInstance() { if (instance == null) { @@ -254,7 +258,7 @@ public class SelectorEngineCssToXPath extends SelectorEngineImpl { } String xsel = cache.get(sel); if (xsel == null) { - xsel = sel.startsWith("./") || sel.startsWith("/") ? sel : css2Xpath(sel); + xsel = sel.startsWith("./") || sel.startsWith("/") ? sel : css2Xpath(sel); cache.put(sel, xsel); } @@ -267,8 +271,8 @@ public class SelectorEngineCssToXPath extends SelectorEngineImpl { if (!SelectorEngine.hasXpathEvaluate()) { throw new RuntimeException("This Browser does not support Xpath selectors.", e); } - console.error("ERROR: xpathEvaluate invalid xpath expression:" - + xsel + " css-selector:" + sel + " " + e.getMessage() + "\n"); + console.error("ERROR: xpathEvaluate invalid xpath expression: " + + xsel + " css-selector: " + sel + " " + e.getMessage() + "\n"); } return elm; } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineImpl.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineImpl.java index fd9d518e..bc2a4587 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineImpl.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineImpl.java @@ -19,6 +19,4 @@ package com.google.gwt.query.client.impl; * Base/Utility class for runtime selector engine implementations. */ public abstract class SelectorEngineImpl implements HasSelector { - - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNative.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNative.java index c8058878..e00fa559 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNative.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNative.java @@ -30,7 +30,8 @@ import com.google.gwt.query.client.js.JsNamedArray; public class SelectorEngineNative extends SelectorEngineImpl { // querySelectorAll unsupported selectors - public static String NATIVE_EXCEPTIONS_REGEXP = "(^[\\./]/.*)|(.*(:contains|:first([^-]|$)|:last([^-]|$)|:even|:odd)).*"; + public static String NATIVE_EXCEPTIONS_REGEXP = + "(^[\\./]/.*)|(.*(:contains|:first([^-]|$)|:last([^-]|$)|:even|:odd)).*"; private static HasSelector impl; @@ -45,9 +46,9 @@ public class SelectorEngineNative extends SelectorEngineImpl { public NodeList<Element> select(String selector, Node ctx) { // querySelectorAllImpl does not support ids starting with a digit. -// if (selector.matches("#[\\w\\-]+")) { -// return SelectorEngine.veryQuickId(selector.substring(1), ctx); -// } else + // if (selector.matches("#[\\w\\-]+")) { + // return SelectorEngine.veryQuickId(selector.substring(1), ctx); + // } else if (selector.contains("!=")) { if (cache == null) { cache = JsNamedArray.create(); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeIE8.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeIE8.java index 42c8dcfe..d31502bc 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeIE8.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeIE8.java @@ -29,7 +29,8 @@ import com.google.gwt.dom.client.NodeList; */ public class SelectorEngineNativeIE8 extends SelectorEngineSizzleIE { - public static String NATIVE_EXCEPTIONS_REGEXP = ".*(:contains|!=|:not|:nth-|:only-|:first|:last|:even|:odd).*"; + public static String NATIVE_EXCEPTIONS_REGEXP = + ".*(:contains|!=|:not|:nth-|:only-|:first|:last|:even|:odd).*"; public NodeList<Element> select(String selector, Node ctx) { if (!SelectorEngine.hasQuerySelector || selector.matches(NATIVE_EXCEPTIONS_REGEXP)) { @@ -42,5 +43,4 @@ public class SelectorEngineNativeIE8 extends SelectorEngineSizzleIE { } } } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMin.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMin.java index 68d9764f..2968a446 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMin.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMin.java @@ -34,11 +34,11 @@ public class SelectorEngineNativeMin extends SelectorEngineImpl { try { return SelectorEngine.querySelectorAllImpl(selector, ctx); } catch (Exception e) { - console.error("GwtQuery: Selector '" + selector + + console.error("GwtQuery: Selector '" + selector + "' is unsupported in this SelectorEngineNativeMin engine." - + " Do not use this syntax or configure your module to use a JS fallback. " + e.getMessage()); + + " Do not use this syntax or configure your module to use a JS fallback. " + + e.getMessage()); return null; } } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMinIE8.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMinIE8.java index 604ce517..dc7e09f6 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMinIE8.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMinIE8.java @@ -17,7 +17,6 @@ package com.google.gwt.query.client.impl; import static com.google.gwt.query.client.GQuery.console; -import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Node; import com.google.gwt.dom.client.NodeList; @@ -35,11 +34,11 @@ public class SelectorEngineNativeMinIE8 extends SelectorEngineImpl { try { return SelectorEngine.querySelectorAllImpl(selector, ctx); } catch (Exception e) { - console.error("GwtQuery: Selector '" + selector + "' is unsupported in this SelectorEngineNativeMinIE8 engine," + console.error("GwtQuery: Selector '" + selector + + "' is unsupported in this SelectorEngineNativeMinIE8 engine," + " check that you are in 'standards mode' or configure your module to use JS fallback. " + e.getMessage()); return null; } } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineSizzle.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineSizzle.java index 8da92e2d..8b17d4fc 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineSizzle.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineSizzle.java @@ -15,7 +15,6 @@ */ package com.google.gwt.query.client.impl; - import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.core.client.JsArray; import com.google.gwt.dom.client.Element; @@ -29,7 +28,6 @@ import com.google.gwt.dom.client.NodeList; */ public class SelectorEngineSizzle extends SelectorEngineImpl { - public static native void initialize() /*-{ (function(){ @@ -924,7 +922,7 @@ GQS.getText = function( elems ) { div = null; // release memory in IE })(); -//if ( document.querySelectorAll ) { +// if ( document.querySelectorAll ) { // (function(){ // var oldGQS = GQS, div = document.createElement("div"); // div.innerHTML = "<p class='TEST'></p>"; @@ -955,7 +953,7 @@ GQS.getText = function( elems ) { // // div = null; // release memory in IE // })(); -//} +// } (function(){ var div = document.createElement("div"); @@ -1039,7 +1037,6 @@ function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) { match = true; break; } - } else if ( GQS.filter( cur, [elem] ).length > 0 ) { match = elem; break; @@ -1091,12 +1088,9 @@ var posProcess = function(selector, context){ window.GQS = GQS; $wnd.GQS = GQS; - })(); - }-*/; - private static native JsArray<Element> select(String selector, Node context, JsArray<Element> results, JsArray<Element> seed) /*-{ return $wnd.GQS(selector, context, results, seed); }-*/; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineSizzleIE.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineSizzleIE.java index 9aad4204..0f4a387b 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineSizzleIE.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineSizzleIE.java @@ -15,7 +15,6 @@ */ package com.google.gwt.query.client.impl; - import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.core.client.JsArray; import com.google.gwt.dom.client.Element; @@ -41,7 +40,6 @@ import com.google.gwt.dom.client.NodeList; */ public class SelectorEngineSizzleIE extends SelectorEngineImpl { - public static native void initialize() /*-{ (function(){ @@ -881,7 +879,6 @@ function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) { match = true; break; } - } else if ( IES.filter( cur, [elem] ).length > 0 ) { match = elem; break; @@ -931,12 +928,9 @@ var posProcess = function(selector, context){ window.IES = IES; $wnd.IES = IES; - })(); - }-*/; - private static native JsArray<Element> select(String selector, Node context, JsArray<Element> results, JsArray<Element> seed) /*-{ return $wnd.IES(selector, context, results, seed); }-*/; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineJS.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineJS.java index 428913b2..deaa396b 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineJS.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineJS.java @@ -37,7 +37,6 @@ import com.google.gwt.query.client.js.JsUtils; */ public class SelectorEngineJS extends SelectorEngineImpl { - /** * Internal class. */ @@ -91,21 +90,22 @@ public class SelectorEngineJS extends SelectorEngineImpl { protected static Sequence getSequence(String expression) { int start = 0, add = 2, max = -1, modVal = -1; - JsRegexp expressionRegExp = new JsRegexp( - "^((odd|even)|([1-9]\\d*)|((([1-9]\\d*)?)n((\\+|\\-)(\\d+))?)|(\\-(([1-9]\\d*)?)n\\+(\\d+)))$"); + JsRegexp expressionRegExp = + new JsRegexp( + "^((odd|even)|([1-9]\\d*)|((([1-9]\\d*)?)n((\\+|\\-)(\\d+))?)|(\\-(([1-9]\\d*)?)n\\+(\\d+)))$"); JsObjectArray<String> pseudoValue = expressionRegExp.exec(expression); if (!truth(pseudoValue)) { return null; } else { - if (truth(pseudoValue.get(2))) { // odd or even + if (truth(pseudoValue.get(2))) { // odd or even start = (eq(pseudoValue.get(2), "odd")) ? 1 : 2; modVal = (start == 1) ? 1 : 0; } else if (JsUtils - .truth(pseudoValue.get(3))) { // single digit + .truth(pseudoValue.get(3))) { // single digit start = Integer.parseInt(pseudoValue.get(3), 10); add = 0; max = start; - } else if (truth(pseudoValue.get(4))) { // an+b + } else if (truth(pseudoValue.get(4))) { // an+b add = truth(pseudoValue.get(6)) ? Integer .parseInt(pseudoValue.get(6), 10) : 1; start = truth(pseudoValue.get(7)) ? Integer.parseInt( @@ -116,7 +116,7 @@ public class SelectorEngineJS extends SelectorEngineImpl { } modVal = (start > add) ? (start - add) % add : ((start == add) ? 0 : start); - } else if (truth(pseudoValue.get(10))) { // -an+b + } else if (truth(pseudoValue.get(10))) { // -an+b add = truth(pseudoValue.get(12)) ? Integer .parseInt(pseudoValue.get(12), 10) : 1; start = max = Integer.parseInt(pseudoValue.get(13), 10); @@ -146,7 +146,7 @@ public class SelectorEngineJS extends SelectorEngineImpl { public static native NodeList<Element> getElementsByClassName(String clazz, Node ctx) /*-{ - return ctx.getElementsByClassName(clazz); + return ctx.getElementsByClassName(clazz); }-*/; public static native boolean isAdded(Node prevRef) /*-{ @@ -214,9 +214,8 @@ public class SelectorEngineJS extends SelectorEngineImpl { private static void getGeneralSiblingNodes(JsNodeArray matchingElms, JsObjectArray<String> nextTag, JsRegexp nextRegExp, Node prevRef) { - while ( - JsUtils.truth((prevRef = SelectorEngine.getNextSibling(prevRef))) - && !isAdded(prevRef)) { + while (JsUtils.truth((prevRef = SelectorEngine.getNextSibling(prevRef))) + && !isAdded(prevRef)) { if (!JsUtils.truth(nextTag) || nextRegExp .test(prevRef.getNodeName())) { setAdded(prevRef, true); @@ -227,9 +226,8 @@ public class SelectorEngineJS extends SelectorEngineImpl { private static void getSiblingNodes(JsNodeArray matchingElms, JsObjectArray<String> nextTag, JsRegexp nextRegExp, Node prevRef) { - while ( - JsUtils.truth(prevRef = SelectorEngine.getNextSibling(prevRef)) - && prevRef.getNodeType() != Node.ELEMENT_NODE) { + while (JsUtils.truth(prevRef = SelectorEngine.getNextSibling(prevRef)) + && prevRef.getNodeType() != Node.ELEMENT_NODE) { } if (JsUtils.truth(prevRef)) { if (!JsUtils.truth(nextTag) || nextRegExp @@ -253,20 +251,20 @@ public class SelectorEngineJS extends SelectorEngineImpl { private static native JsNodeArray subtractArray(JsNodeArray previousMatch, JsNodeArray elementsByPseudo) /*-{ - for (var i=0, src1; (src1=arr1[i]); i++) { - var found = false; - for (var j=0, src2; (src2=arr2[j]); j++) { - if (src2 === src1) { - found = true; - break; - } - } - if (found) { - arr1.splice(i--, 1); - } + for (var i=0, src1; (src1=arr1[i]); i++) { + var found = false; + for (var j=0, src2; (src2=arr2[j]); j++) { + if (src2 === src1) { + found = true; + break; } - return arr; - }-*/; + } + if (found) { + arr1.splice(i--, 1); + } + } + return arr; + }-*/; private JsRegexp cssSelectorRegExp; @@ -277,8 +275,9 @@ public class SelectorEngineJS extends SelectorEngineImpl { public SelectorEngineJS() { selectorSplitRegExp = new JsRegexp("[^\\s]+", "g"); childOrSiblingRefRegExp = new JsRegexp("^(>|\\+|~)$"); - cssSelectorRegExp = new JsRegexp( - "^(\\w+)?(#[\\w\\u00C0-\\uFFFF\\-\\_]+|(\\*))?((\\.[\\w\\u00C0-\\uFFFF\\-_]+)*)?((\\[\\w+(\\^|\\$|\\*|\\||~)?(=[\"']*[\\w\\u00C0-\\uFFFF\\s\\-\\_\\.]+[\"']*)?\\]+)*)?(((:\\w+[\\w\\-]*)(\\((odd|even|\\-?\\d*n?((\\+|\\-)\\d+)?|[\\w\\u00C0-\\uFFFF\\-_]+|((\\w*\\.[\\w\\u00C0-\\uFFFF\\-_]+)*)?|(\\[#?\\w+(\\^|\\$|\\*|\\||~)?=?[\\w\\u00C0-\\uFFFF\\s\\-\\_\\.]+\\]+)|(:\\w+[\\w\\-]*))\\))?)*)?"); + cssSelectorRegExp = + new JsRegexp( + "^(\\w+)?(#[\\w\\u00C0-\\uFFFF\\-\\_]+|(\\*))?((\\.[\\w\\u00C0-\\uFFFF\\-_]+)*)?((\\[\\w+(\\^|\\$|\\*|\\||~)?(=[\"']*[\\w\\u00C0-\\uFFFF\\s\\-\\_\\.]+[\"']*)?\\]+)*)?(((:\\w+[\\w\\-]*)(\\((odd|even|\\-?\\d*n?((\\+|\\-)\\d+)?|[\\w\\u00C0-\\uFFFF\\-_]+|((\\w*\\.[\\w\\u00C0-\\uFFFF\\-_]+)*)?|(\\[#?\\w+(\\^|\\$|\\*|\\||~)?=?[\\w\\u00C0-\\uFFFF\\s\\-\\_\\.]+\\]+)|(:\\w+[\\w\\-]*))\\))?)*)?"); } public NodeList<Element> select(String sel, Node ctx) { @@ -360,8 +359,7 @@ public class SelectorEngineJS extends SelectorEngineImpl { for (int l = 0, ll = prevElem.size(); l < ll; l++) { tagCollectionMatches = getElementsByTagName(splitRule.tag, prevElem.getNode(l)); - for (int m = 0, mlen = tagCollectionMatches.getLength(); m < mlen; - m++) { + for (int m = 0, mlen = tagCollectionMatches.getLength(); m < mlen; m++) { Node tagMatch = tagCollectionMatches.getItem(m); if (!isAdded(tagMatch)) { @@ -431,8 +429,7 @@ public class SelectorEngineJS extends SelectorEngineImpl { for (int r = 0, rlen = matchingElms.size(); r < rlen; r++) { Element current = matchingElms.getElement(r); boolean addElm = false; - for (int s = 0, sl = regExpAttributes.length; - s < sl; s++) { + for (int s = 0, sl = regExpAttributes.length; s < sl; s++) { addElm = false; JsRegexp attributeRegexp = regExpAttributes[s]; String currentAttr = getAttr(current, regExpAttributesStr[s]); @@ -477,7 +474,7 @@ public class SelectorEngineJS extends SelectorEngineImpl { elm.pushAll(prevElem); } - return JsUtils.unique(elm.<JsArray<Element>>cast()).cast(); + return JsUtils.unique(elm.<JsArray<Element>> cast()).cast(); } protected String getAttr(Element current, String name) { @@ -601,9 +598,8 @@ public class SelectorEngineJS extends SelectorEngineImpl { && next.getNodeType() != Node.ELEMENT_NODE) { } } else { - while ( - JsUtils.truth((next = SelectorEngine.getNextSibling(next))) - && next.getNodeType() != Node.ELEMENT_NODE) { + while (JsUtils.truth((next = SelectorEngine.getNextSibling(next))) + && next.getNodeType() != Node.ELEMENT_NODE) { } } if (!JsUtils.truth(next)) { @@ -620,9 +616,8 @@ public class SelectorEngineJS extends SelectorEngineImpl { next = previous = previousMatch.getNode(n); if (previousDir) { - while ( - JsUtils.truth(next = SelectorEngine.getPreviousSibling(next)) - && !JsUtils + while (JsUtils.truth(next = SelectorEngine.getPreviousSibling(next)) + && !JsUtils .eq(next.getNodeName(), previous.getNodeName())) { } } else { @@ -653,7 +648,7 @@ public class SelectorEngineJS extends SelectorEngineImpl { .exec(pseudoValue); JsRegexp notRegExp = new JsRegexp("(^|\\s)" + (JsUtils.truth(notTag) ? notTag.get(1) - : JsUtils.truth(notClass) ? notClass.get(1) : "") + : JsUtils.truth(notClass) ? notClass.get(1) : "") + "(\\s|$)", "i"); if (JsUtils.truth(notAttr)) { String notAttribute = JsUtils.truth(notAttr.get(3)) ? notAttr @@ -769,9 +764,8 @@ public class SelectorEngineJS extends SelectorEngineImpl { prev = next = previous = previousMatch.getNode(k); Node prevParent = previous.getParentNode(); if (prevParent != kParent) { - while ( - JsUtils.truth(prev = SelectorEngine.getPreviousSibling(prev)) - && prev.getNodeType() != Node.ELEMENT_NODE) { + while (JsUtils.truth(prev = SelectorEngine.getPreviousSibling(prev)) + && prev.getNodeType() != Node.ELEMENT_NODE) { } while (JsUtils.truth(next = SelectorEngine.getNextSibling(next)) && next.getNodeType() != Node.ELEMENT_NODE) { @@ -794,9 +788,8 @@ public class SelectorEngineJS extends SelectorEngineImpl { prev = next = previous = previousMatch.getNode(o); Node prevParent = previous.getParentNode(); if (prevParent != oParent) { - while ( - JsUtils.truth(prev = SelectorEngine.getPreviousSibling(prev)) - && !JsUtils + while (JsUtils.truth(prev = SelectorEngine.getPreviousSibling(prev)) + && !JsUtils .eq(prev.getNodeName(), previous.getNodeName())) { } while (JsUtils.truth(next = SelectorEngine.getNextSibling(next)) diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineJSIE.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineJSIE.java index 370d3c6b..f02eb857 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineJSIE.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineJSIE.java @@ -24,14 +24,14 @@ import com.google.gwt.dom.client.Element; public class SelectorEngineJSIE extends SelectorEngineJS { public native String getAttr(Element elm, String attr) /*-{ - switch (attr) { - case "id": - return elm.id; - case "for": - return elm.htmlFor; - case "class": - return elm.className; - } - return elm.getAttribute(attr, 2); + switch (attr) { + case "id": + return elm.id; + case "for": + return elm.htmlFor; + case "class": + return elm.className; + } + return elm.getAttribute(attr, 2); }-*/; } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineSizzleGwt.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineSizzleGwt.java index 64156d60..7bbf1031 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineSizzleGwt.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineSizzleGwt.java @@ -15,7 +15,6 @@ */ package com.google.gwt.query.client.impl.research; - import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.core.client.JsArray; import com.google.gwt.dom.client.Element; @@ -29,7 +28,7 @@ import com.google.gwt.query.client.js.JsUtils; * Sizzle CSS Selector Engine v1.0. * * It has so many JSNI code, the idea is to make an entire implementation - * using Java. Right now it performs worse than pure JSNI implementation + * using Java. Right now it performs worse than pure JSNI implementation. * */ public class SelectorEngineSizzleGwt extends SelectorEngineImpl { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineXPath.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineXPath.java index 63fe9229..73e58740 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineXPath.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineXPath.java @@ -31,7 +31,6 @@ import com.google.gwt.query.client.js.JsObjectArray; import com.google.gwt.query.client.js.JsRegexp; import com.google.gwt.query.client.js.JsUtils; - /** * Runtime selector engine implementation which translates selectors to XPath * and delegates to document.evaluate(). @@ -147,13 +146,14 @@ public class SelectorEngineXPath extends SelectorEngineImpl { } SelectorEngine.xpathEvaluate(xPathExpression, ctx, elm); } - return JsUtils.unique(elm.<JsArray<Element>>cast()).cast(); + return JsUtils.unique(elm.<JsArray<Element>> cast()).cast(); } private void init() { if (cssSelectorRegExp == null) { - cssSelectorRegExp = new JsRegexp( - "^(\\w+)?(#[\\w\\u00C0-\\uFFFF\\-\\_]+|(\\*))?((\\.[\\w\\u00C0-\\uFFFF\\-_]+)*)?((\\[\\w+(\\^|\\$|\\*|\\||~)?(=[\"']*[\\w\\u00C0-\\uFFFF\\s\\-\\_\\.]+[\"']*)?\\]+)*)?(((:\\w+[\\w\\-]*)(\\((odd|even|\\-?\\d*n?((\\+|\\-)\\d+)?|[\\w\\u00C0-\\uFFFF\\-_]+|((\\w*\\.[\\w\\u00C0-\\uFFFF\\-_]+)*)?|(\\[#?\\w+(\\^|\\$|\\*|\\||~)?=?[\\w\\u00C0-\\uFFFF\\s\\-\\_\\.]+\\]+)|(:\\w+[\\w\\-]*))\\))?)*)?(>|\\+|~)?"); + cssSelectorRegExp = + new JsRegexp( + "^(\\w+)?(#[\\w\\u00C0-\\uFFFF\\-\\_]+|(\\*))?((\\.[\\w\\u00C0-\\uFFFF\\-_]+)*)?((\\[\\w+(\\^|\\$|\\*|\\||~)?(=[\"']*[\\w\\u00C0-\\uFFFF\\s\\-\\_\\.]+[\"']*)?\\]+)*)?(((:\\w+[\\w\\-]*)(\\((odd|even|\\-?\\d*n?((\\+|\\-)\\d+)?|[\\w\\u00C0-\\uFFFF\\-_]+|((\\w*\\.[\\w\\u00C0-\\uFFFF\\-_]+)*)?|(\\[#?\\w+(\\^|\\$|\\*|\\||~)?=?[\\w\\u00C0-\\uFFFF\\s\\-\\_\\.]+\\]+)|(:\\w+[\\w\\-]*))\\))?)*)?(>|\\+|~)?"); selectorSplitRegExp = new JsRegexp("[^\\s]+", "g"); combinator = new JsRegexp("(>|\\+|~)"); } @@ -185,9 +185,9 @@ public class SelectorEngineXPath extends SelectorEngineImpl { xpath = "(count(preceding-sibling::*) + 1) mod " + sequence.add + " = " + sequence.modVal + ((sequence.start > 1) ? " and count(preceding-sibling::*) >= " - + (sequence.start - 1) : "") + ((sequence.max > 0) ? - " and count(preceding-sibling::*) <= " + (sequence.max - 1) - : ""); + + (sequence.start - 1) : "") + ((sequence.max > 0) ? + " and count(preceding-sibling::*) <= " + (sequence.max - 1) + : ""); } } } @@ -200,8 +200,8 @@ public class SelectorEngineXPath extends SelectorEngineImpl { } else { xpath = "position() mod " + sequence.add + " = " + sequence.modVal + ((sequence.start > 1) ? " and position() >= " + sequence.start - : "") + ((sequence.max > 0) ? " and position() <= " - + sequence.max : ""); + : "") + ((sequence.max > 0) ? " and position() <= " + + sequence.max : ""); } } } @@ -241,7 +241,6 @@ public class SelectorEngineXPath extends SelectorEngineImpl { function(a,b,c,d) { return @com.google.gwt.query.client.impl.research.SelectorEngineXPath::attrToXPath(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)(a,b || "",c || "",d || ""); }); - }-*/; private native String replaceAttr2(String allAttr) /*-{ diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsCache.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsCache.java index 71d3d3c0..c3b0c5ce 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsCache.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsCache.java @@ -20,9 +20,9 @@ import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.core.client.JsArrayMixed; import com.google.gwt.core.client.JsArrayString; - /** - * A Lightweight JSO class to store data. - */ +/** + * A Lightweight JSO class to store data. + */ public class JsCache extends JavaScriptObject { protected JsCache() { @@ -53,7 +53,7 @@ public class JsCache extends JavaScriptObject { public final native void delete(Object name) /*-{ delete this[name]; }-*/; - + public final void clear() { for (String k : keys()) { delete(k); @@ -69,19 +69,24 @@ public class JsCache extends JavaScriptObject { Object o = get(id); if (o != null && clz != null) { if (o instanceof Double) { - Double d = (Double)o; - if (clz == Float.class) o = d.floatValue(); - else if (clz == Integer.class) o = d.intValue(); - else if (clz == Long.class) o = d.longValue(); - else if (clz == Short.class) o = d.shortValue(); - else if (clz == Byte.class) o = d.byteValue(); + Double d = (Double) o; + if (clz == Float.class) + o = d.floatValue(); + else if (clz == Integer.class) + o = d.intValue(); + else if (clz == Long.class) + o = d.longValue(); + else if (clz == Short.class) + o = d.shortValue(); + else if (clz == Byte.class) + o = d.byteValue(); } else if (clz == Boolean.class && !(o instanceof Boolean)) { o = Boolean.valueOf(String.valueOf(o)); } else if (clz == String.class && !(o instanceof String)) { o = String.valueOf(o); } } - return (T)o; + return (T) o; } public final native <T> T get(Object id) /*-{ @@ -89,7 +94,7 @@ public class JsCache extends JavaScriptObject { }-*/; public final JsCache getCache(int id) { - return (JsCache)get(id); + return (JsCache) get(id); } public final boolean getBoolean(Object id) { @@ -126,7 +131,7 @@ public class JsCache extends JavaScriptObject { public final <T extends JavaScriptObject> T getJavaScriptObject(Object name) { Object o = get(name); - return (o != null && o instanceof JavaScriptObject) ? ((JavaScriptObject)o).<T>cast() : null; + return (o != null && o instanceof JavaScriptObject) ? ((JavaScriptObject) o).<T> cast() : null; } public final native boolean isEmpty() /*-{ @@ -134,7 +139,7 @@ public class JsCache extends JavaScriptObject { return true; }-*/; - public final native boolean contains(Object o)/*-{ + public final native boolean contains(Object o) /*-{ return this.indexOf(o) >= 0; }-*/; @@ -158,11 +163,11 @@ public class JsCache extends JavaScriptObject { return this; }-*/; - public final JsCache put(Object id, Object obj) { + public final JsCache put(Object id, Object obj) { if (obj instanceof Boolean) { - putBoolean(id, ((Boolean)obj).booleanValue()); + putBoolean(id, ((Boolean) obj).booleanValue()); } else if (obj instanceof Number) { - putNumber(id, ((Number)obj).doubleValue()); + putNumber(id, ((Number) obj).doubleValue()); } else { putObject(id, obj); } @@ -203,7 +208,7 @@ public class JsCache extends JavaScriptObject { JsArrayString a = keysImpl(); String[] ret = new String[a.length()]; for (int i = 0; i < a.length(); i++) { - ret[i] = a.get(i); + ret[i] = a.get(i); } return ret; } @@ -211,8 +216,8 @@ public class JsCache extends JavaScriptObject { public final Object[] elements() { String[] keys = keys(); Object[] ret = new Object[keys.length]; - int i=0; - for (String s: keys) { + int i = 0; + for (String s : keys) { ret[i++] = get(s); } return ret; @@ -220,7 +225,7 @@ public class JsCache extends JavaScriptObject { public final String tostring() { String ret = getClass().getName() + "{ "; - for (String k: keys()){ + for (String k : keys()) { ret += k + "=" + get(k) + " "; } return ret + "}"; @@ -240,7 +245,7 @@ public class JsCache extends JavaScriptObject { }-*/; /** - * Throw a NPE when a js is null + * Throw a NPE when a js is null. */ public static final <T extends JavaScriptObject> T checkNull(T js) { if (!GWT.isProdMode() && js == null) { @@ -251,7 +256,7 @@ public class JsCache extends JavaScriptObject { /** * Gets an object wrapped in a js array and boxes it with the appropriate - * Object in the GWT world. + * object in the GWT world. * * It is thought to be called from other jsni code without dealing with casting issues. * diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsClosure.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsClosure.java index e47c4a3b..2481325d 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsClosure.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsClosure.java @@ -31,4 +31,4 @@ public class JsClosure extends JavaScriptObject { public final native void invoke() /*-{ return this(); }-*/; -}
\ No newline at end of file +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsMap.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsMap.java index d912a7f2..010b7a69 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsMap.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsMap.java @@ -17,11 +17,13 @@ package com.google.gwt.query.client.js; import com.google.gwt.core.client.JavaScriptObject; - /** * Lightweight JSO backed implemented of a Map, using Object.hashCode() as key. + * + * @param <S> + * @param <T> */ -final public class JsMap<S, T> extends JavaScriptObject { +public final class JsMap<S, T> extends JavaScriptObject { protected JsMap() { } @@ -32,7 +34,7 @@ final public class JsMap<S, T> extends JavaScriptObject { @SuppressWarnings("unchecked") public T get(int hashCode) { - return (T)c().get(hashCode); + return (T) c().get(hashCode); } public T get(S key) { @@ -43,19 +45,19 @@ final public class JsMap<S, T> extends JavaScriptObject { c().put(key.hashCode(), val); } - public T remove(S key){ + public T remove(S key) { T old = get(key); c().delete(key.hashCode()); return old; } - public T remove(int key){ + public T remove(int key) { T old = get(key); c().delete(key); return old; } - public final String[] keys() { + public String[] keys() { return c().keys(); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsNamedArray.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsNamedArray.java index 552a7d21..5a1b7820 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsNamedArray.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsNamedArray.java @@ -17,11 +17,12 @@ package com.google.gwt.query.client.js; import com.google.gwt.core.client.JavaScriptObject; - /** - * Lightweight JSO backed implemented of a named array + * Lightweight JSO backed implemented of a named array. + * + * @param <T> */ -final public class JsNamedArray<T> extends JavaScriptObject { +public final class JsNamedArray<T> extends JavaScriptObject { protected JsNamedArray() { } @@ -32,14 +33,14 @@ final public class JsNamedArray<T> extends JavaScriptObject { @SuppressWarnings("unchecked") public T get(String key) { - return (T)c().get(key); + return (T) c().get(key); } public void put(String key, T val) { c().put(key, val); } - public final String[] keys() { + public String[] keys() { return c().keys(); } @@ -47,19 +48,19 @@ final public class JsNamedArray<T> extends JavaScriptObject { return c().length(); } - public final Object[] values() { + public Object[] values() { return c().elements(); } - public final boolean exists(String key){ + public boolean exists(String key) { return c().exists(key); } - public final void delete(String key){ + public void delete(String key) { c().delete(key); } - public final static <T> JsNamedArray<T> create() { + public static <T> JsNamedArray<T> create() { return createObject().cast(); } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsNodeArray.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsNodeArray.java index 8b989a50..da8ccf05 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsNodeArray.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsNodeArray.java @@ -26,7 +26,7 @@ import com.google.gwt.dom.client.NodeList; public class JsNodeArray extends NodeList<Element> { public static JsNodeArray create() { - return create((Node)null); + return create((Node) null); } public static native JsNodeArray create(Node node) /*-{ @@ -34,15 +34,15 @@ public class JsNodeArray extends NodeList<Element> { }-*/; public static JsNodeArray create(NodeList<?> nl) { - JsNodeArray ret = create((Node)null); + JsNodeArray ret = create((Node) null); ret.pushAll(nl); return ret; } - protected JsNodeArray(){ + protected JsNodeArray() { } - public final void addNode(Node n){ + public final void addNode(Node n) { c().add(n); } @@ -80,7 +80,7 @@ public class JsNodeArray extends NodeList<Element> { public final Element[] elements() { Element[] ret = new Element[size()]; - for (int i=0 ; i<size(); i++) { + for (int i = 0; i < size(); i++) { ret[i] = getElement(i); } return ret; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsObjectArray.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsObjectArray.java index d8d5e312..3a1b5ee8 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsObjectArray.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsObjectArray.java @@ -19,6 +19,8 @@ import com.google.gwt.core.client.JavaScriptObject; /** * Lightweight JSO based array class that can store objects. + * + * @param <T> */ public final class JsObjectArray<T> extends JavaScriptObject { @@ -33,12 +35,12 @@ public final class JsObjectArray<T> extends JavaScriptObject { return cast(); } - public JsObjectArray<T> add(T...vals) { - for (T t: vals) { + public JsObjectArray<T> add(T... vals) { + for (T t : vals) { if (t instanceof Number) { - c().putNumber(length(), (((Number)t).doubleValue())); + c().putNumber(length(), (((Number) t).doubleValue())); } else if (t instanceof Boolean) { - c().putBoolean(length(), ((Boolean)t).booleanValue()); + c().putBoolean(length(), ((Boolean) t).booleanValue()); } else { c().put(length(), t); } @@ -53,7 +55,7 @@ public final class JsObjectArray<T> extends JavaScriptObject { @SuppressWarnings("unchecked") public T get(int index) { - return (T)c().get(index); + return (T) c().get(index); } public int length() { @@ -71,7 +73,7 @@ public final class JsObjectArray<T> extends JavaScriptObject { public void pushAll(JavaScriptObject prevElem) { c().pushAll(prevElem); } - + public boolean contains(Object o) { return c().contains(o); } @@ -81,9 +83,8 @@ public final class JsObjectArray<T> extends JavaScriptObject { c().remove(o); } } - + public Object[] elements() { return c().elements(); } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsRegexp.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsRegexp.java index b4018cf8..bdf767a9 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsRegexp.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsRegexp.java @@ -70,7 +70,7 @@ public class JsRegexp { return test0(regexp, rule); } - private native JsObjectArray<String> match0(JavaScriptObject regexp, String currentRule)/*-{ + private native JsObjectArray<String> match0(JavaScriptObject regexp, String currentRule) /*-{ return currentRule.match(regexp); }-*/; @@ -78,7 +78,7 @@ public class JsRegexp { return regexp.test(rule); }-*/; - public String getPattern(){ + public String getPattern() { return regexp.toString(); }; } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java index d1833d66..13520fe4 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java @@ -39,6 +39,7 @@ public class JsUtils { */ public static class JsFunction extends Function implements Command { private JavaScriptObject jso = null; + public JsFunction(JavaScriptObject f) { if (JsUtils.isFunction(f)) { jso = f; @@ -49,6 +50,10 @@ public class JsUtils { return jso.equals(obj); } + public int hashCode() { + return jso.hashCode(); + } + private native Object exec(JavaScriptObject f, Object data) /*-{ return @com.google.gwt.query.client.js.JsCache::gwtBox(*)([ f(data) ]); }-*/; @@ -68,7 +73,7 @@ public class JsUtils { * Wraps a GQuery function into a native javascript one so as we can * export Java methods without using JSNI. */ - public static native JavaScriptObject wrapFunction (Function f) /*-{ + public static native JavaScriptObject wrapFunction(Function f) /*-{ return function(r) { var o = @java.util.ArrayList::new()(); for (i in arguments) { @@ -81,6 +86,9 @@ public class JsUtils { } }-*/; + /** + * Default JsUtils implementation. + */ public static class JsUtilsImpl { public native Properties parseJSON(String json) /*-{ return $wnd.JSON.parse(json); @@ -117,6 +125,9 @@ public class JsUtils { }-*/; } + /** + * IE JsUtils implemetation. + */ public static class JsUtilsImplIE6 extends JsUtilsImpl { public static final native Properties evalImpl(String properties) /*-{ return eval(properties); @@ -136,13 +147,13 @@ public class JsUtils { // @see https://github.com/douglascrockford/JSON-js/blob/master/json2.js Properties prop = js.cast(); String ret = ""; - for (String k : prop.keys()){ + for (String k : prop.keys()) { String ky = k.matches("\\d+") ? k : "\"" + k + "\""; JsCache o = prop.getArray(k).cast(); if (o != null) { ret += ky + ":["; - for (int i = 0, l = o.length(); i < l ; i++) { - Properties p = o.<JsCache>cast().getJavaScriptObject(i); + for (int i = 0, l = o.length(); i < l; i++) { + Properties p = o.<JsCache> cast().getJavaScriptObject(i); if (p != null) { ret += p.toJsonString() + ","; } else { @@ -159,9 +170,9 @@ public class JsUtils { } } } - return "{" + ret.replaceAll(",\\s*([\\]}]|$)","$1") - .replaceAll("([:,\\[])\"(-?[\\d\\.]+|null|false|true)\"", "$1$2") - + "}"; + return "{" + ret.replaceAll(",\\s*([\\]}]|$)", "$1") + .replaceAll("([:,\\[])\"(-?[\\d\\.]+|null|false|true)\"", "$1$2") + + "}"; } @Override @@ -201,29 +212,30 @@ public class JsUtils { * Returns a property present in a javascript object. */ public static <T> T prop(JavaScriptObject o, Object id, Class<? extends T> type) { - return o == null ? null : o.<JsCache>cast().get(id, type); + return o == null ? null : o.<JsCache> cast().get(id, type); } /** * Returns a property present in a javascript object. */ public static <T> T prop(JavaScriptObject o, Object id) { - return o == null ? null : o.<JsCache>cast().<T>get(id); + return o == null ? null : o.<JsCache> cast().<T> get(id); } /** - * Set a property to a javascript object + * Set a property to a javascript object. */ public static void prop(JavaScriptObject o, Object id, Object val) { if (o != null) { - o.<JsCache>cast().put(id, val); + o.<JsCache> cast().put(id, val); } } /** - * Camelize style property names. for instance: font-name -> fontName + * Camelize style property names. + * for instance: font-name -> fontName */ - public static native String camelize(String s)/*-{ + public static native String camelize(String s) /*-{ return s.replace(/\-(\w)/g, function(all, letter) { return letter.toUpperCase(); }); @@ -256,7 +268,8 @@ public class JsUtils { } /** - * Use the method in the gquery class $(elem).cur(prop, force); + * Use the method in the gquery class. + * $(elem).cur(prop, force); */ @Deprecated public static double cur(Element elem, String prop, boolean force) { @@ -289,28 +302,29 @@ public class JsUtils { * Check if an object has already a property with name <code>name</code> * defined. */ - public static native boolean hasProperty(JavaScriptObject o, String name)/*-{ + public static native boolean hasProperty(JavaScriptObject o, String name) /*-{ return o && name in o; }-*/; /** * Check whether an element has an attribute, this is here since GWT Element.getAttribute * implementation returns an empty string instead of null when the attribute is not - * present + * present. */ - public static native boolean hasAttribute(Element o, String name)/*-{ + public static native boolean hasAttribute(Element o, String name) /*-{ return !!(o && o.getAttribute(name)); }-*/; /** - * Hyphenize style property names. for instance: fontName -> font-name + * Hyphenize style property names. + * for instance: fontName -> font-name */ public static native String hyphenize(String name) /*-{ return name.replace(/([A-Z])/g, "-$1").toLowerCase(); }-*/; /** - * Check is a javascript object can be used as an array + * Check is a javascript object can be used as an array. */ public static native boolean isArray(JavaScriptObject o) /*-{ return Object.prototype.toString.call(o) == '[object Array]' @@ -318,28 +332,29 @@ public class JsUtils { }-*/; /** - * Check is a javascript object is a FormData + * Check is a javascript object is a FormData. */ public static native boolean isFormData(JavaScriptObject o) /*-{ return Object.prototype.toString.call(o) == '[object FormData]'; }-*/; /** - * Return whether the event was prevented + * Return whether the event was prevented. */ - public static native boolean isDefaultPrevented(JavaScriptObject e)/*-{ + public static native boolean isDefaultPrevented(JavaScriptObject e) /*-{ return e.defaultPrevented || e.returnValue === false || e.getPreventDefault && e.getPreventDefault() ? true : false; }-*/; /** - * Return whether a node is detached to the dom + * Return whether a node is detached to the DOM. + * * Be careful : This method works only on node that should be inserted within the body node. */ public static boolean isDetached(Node n) { assert n != null; - if ("html".equalsIgnoreCase(n.getNodeName())){ + if ("html".equalsIgnoreCase(n.getNodeName())) { return false; } @@ -347,28 +362,28 @@ public class JsUtils { } /** - * Check is a javascript object can be cast to an Element + * Check is a javascript object can be cast to an Element. */ public static native boolean isElement(Object o) /*-{ return !!o && 'nodeType' in o && 'nodeName' in o; }-*/; /** - * Check is a javascript object can be cast to an Event + * Check is a javascript object can be cast to an Event. */ public static boolean isEvent(JavaScriptObject o) { return hasProperty(o, "currentTarget"); } /** - * Check is a javascript object is a function + * Check is a javascript object is a function. */ public static native boolean isFunction(JavaScriptObject o) /*-{ return Object.prototype.toString.call(o) == '[object Function]'; }-*/; /** - * Check is a javascript can be cast to a node list + * Check is a javascript can be cast to a node list. */ public static native boolean isNodeList(JavaScriptObject o) /*-{ var r = Object.prototype.toString.call(o); @@ -377,14 +392,14 @@ public class JsUtils { }-*/; /** - * Check is a javascript object is a Window + * Check is a javascript object is a Window. */ public static boolean isWindow(JavaScriptObject o) { return hasProperty(o, "alert"); } /** - * Check if an element is a DOM or a XML node + * Check if an element is a DOM or a XML node. */ public static boolean isXML(Node o) { return o == null ? false @@ -461,11 +476,10 @@ public class JsUtils { /** * Utility method to cast objects to array of string in production. */ - public static native String[] castArrayString(Object a)/*-{ + public static native String[] castArrayString(Object a) /*-{ return a }-*/; - /** * Call via jsni any arbitrary function present in a Javascript object. * @@ -486,10 +500,12 @@ public class JsUtils { * @return the javascript object returned by the jsni method or null. */ public static <T> T runJavascriptFunction(JavaScriptObject o, String meth, Object... args) { - return runJavascriptFunctionImpl(o, meth, JsObjectArray.create().add(args).<JsArrayMixed>cast()); + return runJavascriptFunctionImpl(o, meth, JsObjectArray.create().add(args) + .<JsArrayMixed> cast()); } - private static native <T> T runJavascriptFunctionImpl(JavaScriptObject o, String meth, JsArrayMixed args) /*-{ + private static native <T> T runJavascriptFunctionImpl(JavaScriptObject o, String meth, + JsArrayMixed args) /*-{ return (f = o && o[meth]) && @com.google.gwt.query.client.js.JsUtils::isFunction(*)(f) && @com.google.gwt.query.client.js.JsCache::gwtBox(*)([f.apply(o, args)]); @@ -510,7 +526,7 @@ public class JsUtils { }-*/; /** - * Remove duplicates from an elements array + * Remove duplicates from an elements array. */ public static JsArray<Element> unique(JsArray<Element> a) { return utilsImpl.unique(a); @@ -526,6 +542,7 @@ public class JsUtils { /** * Returns a QueryString representation of a JavascriptObject. + * * TODO: jquery implementation accepts a second parameter (traditional) */ public static String param(JavaScriptObject js) { @@ -535,13 +552,13 @@ public class JsUtils { ret += ret.isEmpty() ? "" : "&"; JsCache o = prop.getArray(k).cast(); if (o != null) { - for (int i = 0, l = o.length(); i < l ; i++) { + for (int i = 0, l = o.length(); i < l; i++) { ret += i > 0 ? "&" : ""; - Properties p = o.<JsCache>cast().getJavaScriptObject(i); + Properties p = o.<JsCache> cast().getJavaScriptObject(i); if (p != null) { ret += k + "[]=" + p.toJsonString(); } else { - ret += k + "[]=" + o.getString(i) ; + ret += k + "[]=" + o.getString(i); } } } else { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Effects.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Effects.java index 64818c9c..acb7fc17 100755 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Effects.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Effects.java @@ -35,7 +35,7 @@ public class Effects extends QueuePlugin<Effects> { /** * Class to access protected methods in Animation. */ - public static abstract class GQAnimation extends Animation { + public abstract static class GQAnimation extends Animation { private static final String ACTUAL_ANIMATION = "EffectsRunnning"; @@ -47,20 +47,24 @@ public class Effects extends QueuePlugin<Effects> { e = element; return this; } + protected GQAnimation setProperties(Properties properties) { prps = properties == null ? Properties.create() : properties; return this; } + protected void onStart() { // Mark this animation as actual, so as we can stop it in the GQuery.stop() method $(e).data(ACTUAL_ANIMATION, this); super.onStart(); } + protected void onComplete() { // avoid memory leak (issue #132) $(e).removeData(ACTUAL_ANIMATION); super.onComplete(); } + public void cancel() { // avoid memory leak (issue #132) $(e).removeData(ACTUAL_ANIMATION); @@ -100,6 +104,7 @@ public class Effects extends QueuePlugin<Effects> { anim.cancel(); } } + public void f(Element e) { anim.run(duration); } @@ -125,8 +130,8 @@ public class Effects extends QueuePlugin<Effects> { * Example: * * <pre class="code"> - * //move the element from its original position to the position top:500px and left:500px for 400ms. - * //use a swing easing function for the transition + * // move the element from its original position to the position top:500px and left:500px for 400ms. + * // use a swing easing function for the transition * $("#foo").animate(Properties.create("{top:'500px',left:'500px'}"), 400, EasingCurve.swing); * // Change the width and border attributes of a table * $("table").animate(Properties.create("{$width: '500', $border: '10'}"), 400, EasingCurve.linear); @@ -142,8 +147,8 @@ public class Effects extends QueuePlugin<Effects> { * Example: * * <pre class="code"> - * //move the element from its original position to 500px to the left and 5OOpx down for 400ms. - * //use a swing easing function for the transition + * // move the element from its original position to 500px to the left and 5OOpx down for 400ms. + * // use a swing easing function for the transition * $("#foo").animate(Properties.create("{top:'+=500px',left:'+=500px'}"), 400, Easing.SWING); * </pre> * @@ -157,7 +162,7 @@ public class Effects extends QueuePlugin<Effects> { * $("#foo").animate($$("{backgroundColor:'red', color:'#ffffff', borderColor:'rgb(129, 0, 70)'}"), 400, EasingCurve.swing); * </pre> * - * @param p a {@link Properties} object containing css properties to animate. + * @param stringOrProperties object containing css properties to animate. * @param funcs an array of {@link Function} called once the animation is * complete * @param duration the duration in milliseconds of the animation @@ -175,7 +180,7 @@ public class Effects extends QueuePlugin<Effects> { duration = Math.abs(duration); - for (Element e: elements()) { + for (Element e : elements()) { if (Fx.css3) { new TransitionsClipAnimation(easing, e, p, funcs).run(duration); } else { @@ -200,7 +205,7 @@ public class Effects extends QueuePlugin<Effects> { * Example: * * <pre class="code"> - * //move the element from its original position to left:500px for 500ms + * // move the element from its original position to left:500px for 500ms * $("#foo").animate("left:'500'"); * // Change the width attribute of a table * $("table").animate("$width:'500'"), 400, EasingCurve.swing); @@ -216,7 +221,7 @@ public class Effects extends QueuePlugin<Effects> { * Example: * * <pre class="code"> - * //move the element from its original position to 500px to the left for 500ms and + * // move the element from its original position to 500px to the left for 500ms and * // change the background color of the element at the end of the animation * $("#foo").animate("left:'+=500'", new Function(){ * @@ -238,7 +243,7 @@ public class Effects extends QueuePlugin<Effects> { * $("#foo").animate("backgroundColor:'red', color:'#ffffff', borderColor:'rgb(129, 0, 70)'"); * </pre> * - * @param prop the property to animate : "cssName:'value'" + * @param stringOrProperties the property to animate : "cssName:'value'" * @param funcs an array of {@link Function} called once the animation is * complete */ @@ -260,7 +265,7 @@ public class Effects extends QueuePlugin<Effects> { * Example: * * <pre class="code"> - * //move the element from its original position to left:500px for 2s + * // move the element from its original position to left:500px for 2s * $("#foo").animate("left:'500px'", 2000); * // Change the width attribute of a table * $("table").animate("$width:'500'"), 400); @@ -276,7 +281,7 @@ public class Effects extends QueuePlugin<Effects> { * Example: * * <pre class="code"> - * //move the element from its original position to 500px to the left for 1000ms and + * // move the element from its original position to 500px to the left for 1000ms and * // change the background color of the element at the end of the animation * $("#foo").animate("left:'+=500'", 1000, new Function(){ * public void f(Element e){ @@ -285,7 +290,6 @@ public class Effects extends QueuePlugin<Effects> { * }); * </pre> * - * * For color css properties, values can be specified via hexadecimal or rgb or * literal values. * @@ -295,8 +299,7 @@ public class Effects extends QueuePlugin<Effects> { * $("#foo").animate("backgroundColor:'red', color:'#ffffff', borderColor:'rgb(129, 0, 70)', 1000"); * </pre> * - * - * @param prop the property to animate : "cssName:'value'" + * @param stringOrProperties the property to animate : "cssName:'value'" * @param funcs an array of {@link Function} called once the animation is * complete * @param duration the duration in milliseconds of the animation diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java index 101ae0b9..84ce65dd 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java @@ -40,7 +40,8 @@ public class Events extends GQuery { * Don't apply events on text and comment nodes !! */ private static boolean isEventCapable(Node n) { - return JsUtils.isWindow(n) || JsUtils.isElement(n) && n.getNodeType() != 3 && n.getNodeType() != 8; + return JsUtils.isWindow(n) || JsUtils.isElement(n) && n.getNodeType() != 3 + && n.getNodeType() != 8; } public Events(GQuery gq) { @@ -107,16 +108,14 @@ public class Events extends GQuery { return this; } - public GQuery die(int eventbits, String nameSpace) { EventsListener.getInstance(Element.is(currentContext) ? (Element) currentContext : body).die( eventbits, nameSpace, null, null, currentSelector); return this; } - public GQuery die(int eventbits) { - return die(eventbits, null); + return die(eventbits, null); } /** @@ -132,14 +131,12 @@ public class Events extends GQuery { public GQuery live(int eventbits, final Object data, Function... funcs) { return live(eventbits, null, data, funcs); - } public GQuery live(int eventbits, String nameSpace, final Object data, Function... funcs) { EventsListener.getInstance(Element.is(currentContext) ? (Element) currentContext : body).live( eventbits, nameSpace, null, null, currentSelector, data, funcs); return this; - } public GQuery live(String eventName, final Object data, Function... funcs) { @@ -185,7 +182,6 @@ public class Events extends GQuery { } return bind("mouseleave", null, fs); - } /** @@ -300,12 +296,12 @@ public class Events extends GQuery { GqEvent.setOriginalEventType(e, originalEventName); } - if ("submit".equals(htmlEvent)){ + if ("submit".equals(htmlEvent)) { Function submitFunction = new Function() { public void f(Element e) { // first submit the form then call the others functions if (FormElement.is(e)) { - e.<FormElement>cast().submit(); + e.<FormElement> cast().submit(); } callHandlers(e, getEvent(), functions); } @@ -400,7 +396,7 @@ public class Events extends GQuery { // Ie6-8 don't dispatch bitless event if ((browser.ie6 || browser.ie8) && Event.getTypeInt(evt.getType()) == -1) { - bubbleEventForIE(e, evt.<Event>cast()); + bubbleEventForIE(e, evt.<Event> cast()); } else { e.dispatchEvent(evt); } @@ -424,16 +420,16 @@ public class Events extends GQuery { } /** - * Only valid for IE6-8 + * Only valid for IE6-8. * @param event * @return */ private boolean isEventPropagationStopped(Event event) { // trick to avoid jnsi - return event.<Element>cast().getPropertyBoolean("cancelBubble"); + return event.<Element> cast().getPropertyBoolean("cancelBubble"); } - private void callHandlers(Element e, NativeEvent evt, Function... functions){ + private void callHandlers(Element e, NativeEvent evt, Function... functions) { for (Function f : functions) { f.setEvent(Event.as(evt)); f.f(e); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEffects.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEffects.java index f0af09b8..eb63a22a 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEffects.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEffects.java @@ -14,21 +14,16 @@ * the License. */ package com.google.gwt.query.client.plugins; -import com.google.gwt.animation.client.Animation; -import com.google.gwt.dom.client.Element; + import com.google.gwt.query.client.Function; -import com.google.gwt.query.client.GQuery; -import com.google.gwt.query.client.Properties; -import com.google.gwt.query.client.plugins.effects.ClipAnimation; -import com.google.gwt.query.client.plugins.effects.ClipAnimation.Direction; -import com.google.gwt.query.client.plugins.effects.Fx; -import com.google.gwt.query.client.plugins.effects.PropertiesAnimation.Easing; -import com.google.gwt.query.client.plugins.effects.PropertiesAnimation.EasingCurve; -import com.google.gwt.query.client.plugins.effects.TransitionsAnimation.TransitionsClipAnimation; -import com.google.gwt.query.client.GQuery.*; import com.google.gwt.query.client.LazyBase; +import com.google.gwt.query.client.plugins.effects.PropertiesAnimation.Easing; -public interface LazyEffects<T> extends LazyBase<T>{ +/** + * LazyEffects. + * @param <T> + */ +public interface LazyEffects<T> extends LazyBase<T> { /** * The animate() method allows you to create animation effects on any numeric @@ -44,8 +39,8 @@ public interface LazyEffects<T> extends LazyBase<T>{ * Example: * * <pre class="code"> - * //move the element from its original position to the position top:500px and left:500px for 400ms. - * //use a swing easing function for the transition + * // move the element from its original position to the position top:500px and left:500px for 400ms. + * // use a swing easing function for the transition * $("#foo").animate(Properties.create("{top:'500px',left:'500px'}"), 400, EasingCurve.swing); * // Change the width and border attributes of a table * $("table").animate(Properties.create("{$width: '500', $border: '10'}"), 400, EasingCurve.linear); @@ -61,8 +56,8 @@ public interface LazyEffects<T> extends LazyBase<T>{ * Example: * * <pre class="code"> - * //move the element from its original position to 500px to the left and 5OOpx down for 400ms. - * //use a swing easing function for the transition + * // move the element from its original position to 500px to the left and 5OOpx down for 400ms. + * // use a swing easing function for the transition * $("#foo").animate(Properties.create("{top:'+=500px',left:'+=500px'}"), 400, Easing.SWING); * </pre> * @@ -76,7 +71,7 @@ public interface LazyEffects<T> extends LazyBase<T>{ * $("#foo").animate($$("{backgroundColor:'red', color:'#ffffff', borderColor:'rgb(129, 0, 70)'}"), 400, EasingCurve.swing); * </pre> * - * @param p a {@link Properties} object containing css properties to animate. + * @param stringOrProperties {@link Properties} object containing css properties to animate. * @param funcs an array of {@link Function} called once the animation is * complete * @param duration the duration in milliseconds of the animation @@ -99,7 +94,7 @@ public interface LazyEffects<T> extends LazyBase<T>{ * Example: * * <pre class="code"> - * //move the element from its original position to left:500px for 500ms + * // move the element from its original position to left:500px for 500ms * $("#foo").animate("left:'500'"); * // Change the width attribute of a table * $("table").animate("$width:'500'"), 400, EasingCurve.swing); @@ -115,7 +110,7 @@ public interface LazyEffects<T> extends LazyBase<T>{ * Example: * * <pre class="code"> - * //move the element from its original position to 500px to the left for 500ms and + * // move the element from its original position to 500px to the left for 500ms and * // change the background color of the element at the end of the animation * $("#foo").animate("left:'+=500'", new Function(){ * @@ -137,7 +132,7 @@ public interface LazyEffects<T> extends LazyBase<T>{ * $("#foo").animate("backgroundColor:'red', color:'#ffffff', borderColor:'rgb(129, 0, 70)'"); * </pre> * - * @param prop the property to animate : "cssName:'value'" + * @param stringOrProperties the property to animate : "cssName:'value'" * @param funcs an array of {@link Function} called once the animation is * complete */ @@ -157,7 +152,7 @@ public interface LazyEffects<T> extends LazyBase<T>{ * Example: * * <pre class="code"> - * //move the element from its original position to left:500px for 2s + * // move the element from its original position to left:500px for 2s * $("#foo").animate("left:'500px'", 2000); * // Change the width attribute of a table * $("table").animate("$width:'500'"), 400); @@ -173,7 +168,7 @@ public interface LazyEffects<T> extends LazyBase<T>{ * Example: * * <pre class="code"> - * //move the element from its original position to 500px to the left for 1000ms and + * // move the element from its original position to 500px to the left for 1000ms and * // change the background color of the element at the end of the animation * $("#foo").animate("left:'+=500'", 1000, new Function(){ * public void f(Element e){ @@ -182,7 +177,6 @@ public interface LazyEffects<T> extends LazyBase<T>{ * }); * </pre> * - * * For color css properties, values can be specified via hexadecimal or rgb or * literal values. * @@ -192,8 +186,7 @@ public interface LazyEffects<T> extends LazyBase<T>{ * $("#foo").animate("backgroundColor:'red', color:'#ffffff', borderColor:'rgb(129, 0, 70)', 1000"); * </pre> * - * - * @param prop the property to animate : "cssName:'value'" + * @param stringOrProperties the property to animate : "cssName:'value'" * @param funcs an array of {@link Function} called once the animation is * complete * @param duration the duration in milliseconds of the animation diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEvents.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEvents.java index 081e1702..55404170 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEvents.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEvents.java @@ -12,21 +12,17 @@ * the License. */ package com.google.gwt.query.client.plugins; -import com.google.gwt.dom.client.Element; -import com.google.gwt.dom.client.FormElement; + import com.google.gwt.dom.client.NativeEvent; -import com.google.gwt.dom.client.Node; import com.google.gwt.query.client.Function; import com.google.gwt.query.client.GQuery; -import com.google.gwt.query.client.js.JsUtils; -import com.google.gwt.query.client.plugins.events.EventsListener; -import com.google.gwt.query.client.plugins.events.EventsListener.SpecialEvent; -import com.google.gwt.query.client.plugins.events.GqEvent; -import com.google.gwt.user.client.Event; -import com.google.gwt.query.client.GQuery.*; import com.google.gwt.query.client.LazyBase; -public interface LazyEvents<T> extends LazyBase<T>{ +/** + * LazyEvents. + * @param <T> + */ +public interface LazyEvents<T> extends LazyBase<T> { /** * Binds a set of handlers to a particular Event for each matched element. diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyWidgets.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyWidgets.java index 8c40c293..f08a0538 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyWidgets.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyWidgets.java @@ -14,36 +14,30 @@ * the License. */ package com.google.gwt.query.client.plugins; -import java.util.ArrayList; -import java.util.List; -import com.google.gwt.dom.client.Element; -import com.google.gwt.query.client.GQuery; -import com.google.gwt.query.client.plugins.widgets.ButtonWidgetFactory; -import com.google.gwt.query.client.plugins.widgets.HtmlPanelWidgetFactory; -import com.google.gwt.query.client.plugins.widgets.LabelWidgetFactory; -import com.google.gwt.query.client.plugins.widgets.PasswordTextBoxWidgetFactory; -import com.google.gwt.query.client.plugins.widgets.TextAreaWidgetFactory; -import com.google.gwt.query.client.plugins.widgets.TextBoxWidgetFactory; + +import com.google.gwt.query.client.LazyBase; import com.google.gwt.query.client.plugins.widgets.WidgetFactory; import com.google.gwt.query.client.plugins.widgets.WidgetInitializer; -import com.google.gwt.query.client.plugins.widgets.WidgetsUtils; import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.PasswordTextBox; import com.google.gwt.user.client.ui.TextArea; import com.google.gwt.user.client.ui.TextBox; import com.google.gwt.user.client.ui.Widget; -import com.google.gwt.query.client.GQuery.*; -import com.google.gwt.query.client.LazyBase; -public interface LazyWidgets<T> extends LazyBase<T>{ +/** + * LazyWidgets. + * @param <T> + */ +public interface LazyWidgets<T> extends LazyBase<T> { /** * Try to create a widget using the given factory and the given options for * each element of the query. Returns a new gquery set of elements with the * new widgets created. */ - <W extends Widget> LazyWidgets<T> widgets(WidgetFactory<W> factory, WidgetInitializer<W> initializers); + <W extends Widget> LazyWidgets<T> widgets(WidgetFactory<W> factory, + WidgetInitializer<W> initializers); /** * Create a {@link Button} widget for each selected element. diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/MouseOptions.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/MouseOptions.java index 4d010276..772f8e9f 100755 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/MouseOptions.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/MouseOptions.java @@ -16,7 +16,7 @@ package com.google.gwt.query.client.plugins; /** - * Object use to configure a Plugin extending {@link MousePlugin} + * Object use to configure a Plugin extending {@link MousePlugin}. * */ public class MouseOptions { @@ -58,7 +58,7 @@ public class MouseOptions { } /** - * Prevents starting of the plugin on specified elements + * Prevents starting of the plugin on specified elements. * * @param cancel * array of css selectors @@ -89,6 +89,6 @@ public class MouseOptions { protected void initDefault() { delay = 0; distance = 1; // by default, the mouse have to move one pixel ! - cancel = new String[] { "input", "option" }; + cancel = new String[] {"input", "option"}; } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/MousePlugin.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/MousePlugin.java index aca8db05..2202bc71 100755 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/MousePlugin.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/MousePlugin.java @@ -52,7 +52,7 @@ public abstract class MousePlugin extends UiPlugin { protected abstract String getPluginName(); /** - * This method initialize all needed handlers + * This method initialize all needed handlers. * */ protected void initMouseHandler(MouseOptions options) { @@ -67,7 +67,6 @@ public abstract class MousePlugin extends UiPlugin { return true; } return mouseDown(e, GqEvent.create(event)); - } }).bind(Event.ONTOUCHSTART, getPluginName(), (Object) null, new Function() { public boolean f(com.google.gwt.user.client.Event event) { @@ -77,7 +76,6 @@ public abstract class MousePlugin extends UiPlugin { touchSupported = true; return mouseDown(e, GqEvent.create(event)); - } }).bind(Event.ONCLICK, getPluginName(), (Object) null, new Function() { @Override @@ -96,20 +94,17 @@ public abstract class MousePlugin extends UiPlugin { } }); } - } /** * Test if the mouse down event must be handled by the plugin or not. - * */ protected boolean mouseCapture(Element draggable, GqEvent event) { return true; } /** - * Method called when mouse click - * + * Method called when mouse click. */ protected boolean mouseClick(Element element, GqEvent event) { return true; @@ -119,8 +114,7 @@ public abstract class MousePlugin extends UiPlugin { * Method called when mouse down occur on the element. * * You should not override this method. Instead, override {@link #mouseStart(Element, GqEvent)} - * method - * + * method. */ protected boolean mouseDown(Element element, GqEvent event) { @@ -150,7 +144,7 @@ public abstract class MousePlugin extends UiPlugin { bindOtherEvents(element); - if (!touchSupported){ //click event are not triggered if we call preventDefault on touchstart event. + if (!touchSupported) { // click event are not triggered if we call preventDefault on touchstart event. event.getOriginalEvent().preventDefault(); } @@ -160,8 +154,7 @@ public abstract class MousePlugin extends UiPlugin { } /** - * Method called when the mouse is dragging - * + * Method called when the mouse is dragging. */ protected abstract boolean mouseDrag(Element element, GqEvent event); @@ -198,8 +191,7 @@ public abstract class MousePlugin extends UiPlugin { protected abstract boolean mouseStart(Element element, GqEvent event); /** - * Method called when the mouse button is released - * + * Method called when the mouse button is released. */ protected abstract boolean mouseStop(Element element, GqEvent event); @@ -207,8 +199,7 @@ public abstract class MousePlugin extends UiPlugin { * Method called when mouse is released.. * * You should not override this method. Instead, override {@link #mouseStop(Element, GqEvent)} - * method - * + * method. */ protected boolean mouseUp(Element element, GqEvent event) { @@ -220,7 +211,6 @@ public abstract class MousePlugin extends UiPlugin { } return true; - } private void bindOtherEvents(final Element element) { @@ -253,9 +243,7 @@ public abstract class MousePlugin extends UiPlugin { return false; } }); - } - } private boolean delayConditionMet() { @@ -280,13 +268,13 @@ public abstract class MousePlugin extends UiPlugin { return mouseDistance >= neededDistance; } - private native boolean isEventAlreadyHandled(GqEvent event)/*-{ - var result = event.mouseHandled ? event.mouseHandled : false; - return result; + private native boolean isEventAlreadyHandled(GqEvent event) /*-{ + var result = event.mouseHandled ? event.mouseHandled : false; + return result; }-*/; - private native void markEventAsHandled(GqEvent event)/*-{ - event.mouseHandled = true; + private native void markEventAsHandled(GqEvent event) /*-{ + event.mouseHandled = true; }-*/; private boolean notHandleMouseDown(Element element, GqEvent mouseDownEvent) { @@ -300,7 +288,6 @@ public abstract class MousePlugin extends UiPlugin { } return isNotBoutonLeft || isElementCancel || !mouseCapture(element, mouseDownEvent); - } private void reset(GqEvent nativeEvent) { @@ -333,5 +320,4 @@ public abstract class MousePlugin extends UiPlugin { return e.getClientY(); } } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/QueuePlugin.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/QueuePlugin.java index e83625d5..8951ccad 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/QueuePlugin.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/QueuePlugin.java @@ -15,9 +15,6 @@ */ package com.google.gwt.query.client.plugins; -import java.util.LinkedList; -import java.util.Queue; - import com.google.gwt.dom.client.Element; import com.google.gwt.query.client.Function; import com.google.gwt.query.client.GQuery; @@ -25,8 +22,13 @@ import com.google.gwt.query.client.Promise; import com.google.gwt.query.client.plugins.deferred.Callbacks; import com.google.gwt.user.client.Timer; +import java.util.LinkedList; +import java.util.Queue; + /** * Class used in plugins which need a queue system. + * + * @param <T> */ public class QueuePlugin<T extends QueuePlugin<?>> extends GQuery { @@ -80,14 +82,14 @@ public class QueuePlugin<T extends QueuePlugin<?>> extends GQuery { } /** - * remove all queued functions from the effects queue + * remove all queued functions from the effects queue. */ public T clearQueue() { return clearQueue(DEFAULT_NAME); } /** - * remove all queued function from the named queue + * remove all queued function from the named queue. */ @SuppressWarnings("unchecked") public T clearQueue(String name) { @@ -98,21 +100,21 @@ public class QueuePlugin<T extends QueuePlugin<?>> extends GQuery { } /** - * Add a delay in the effects queue + * Add a delay in the effects queue. */ public T delay(int milliseconds, Function... f) { return delay(milliseconds, DEFAULT_NAME, f); } /** - * Add a delay in the named queue + * Add a delay in the named queue. */ @SuppressWarnings("unchecked") public T delay(int milliseconds, String name, Function... funcs) { for (Element e : elements()) { queue(e, name, new DelayFunction(e, name, milliseconds, funcs)); } - return (T)this; + return (T) this; } /** @@ -134,15 +136,15 @@ public class QueuePlugin<T extends QueuePlugin<?>> extends GQuery { } /** - * Returns a dynamically generated Promise that is resolved once all actions + * Returns a dynamically generated Promise that is resolved once all actions * in the queue have ended. */ public Promise promise() { return promise(DEFAULT_NAME); } - + /** - * Returns a dynamically generated Promise that is resolved once all actions + * Returns a dynamically generated Promise that is resolved once all actions * in the named queue have ended. */ public Promise promise(final String name) { @@ -154,25 +156,25 @@ public class QueuePlugin<T extends QueuePlugin<?>> extends GQuery { int count = 1; // Inner functions don't have constructors, we use a block to initialize it { - for (Element elem: elements()) { - // Add this resolve function only to those elements with active queue + for (Element elem : elements()) { + // Add this resolve function only to those elements with active queue if (queue(elem, name, null) != null) { emptyHooks(elem, name).add(this); count++; } } } - + public void f() { if (--count == 0) { dfd.resolve(QueuePlugin.this); } } }; - + // Run the function and resolve it in case there are not elements with active queue resolve.f(this, name); - + return dfd.promise(); } @@ -190,7 +192,7 @@ public class QueuePlugin<T extends QueuePlugin<?>> extends GQuery { */ public int queue(String name) { Queue<?> q = isEmpty() ? null : queue(get(0), name, null); - return q == null? 0 : q.size(); + return q == null ? 0 : q.size(); } /** @@ -204,7 +206,7 @@ public class QueuePlugin<T extends QueuePlugin<?>> extends GQuery { queue(e, DEFAULT_NAME, f); } } - return (T)this; + return (T) this; } /** @@ -213,12 +215,12 @@ public class QueuePlugin<T extends QueuePlugin<?>> extends GQuery { */ @SuppressWarnings("unchecked") public T queue(final String name, Function... funcs) { - for (final Function f: funcs) { - for (Element e: elements()) { + for (final Function f : funcs) { + for (Element e : elements()) { queue(e, name, f); } } - return (T)this; + return (T) this; } /** @@ -315,7 +317,7 @@ public class QueuePlugin<T extends QueuePlugin<?>> extends GQuery { runNext(elem, name, q); } } - + private void runNext(Element elem, String name, Queue<? extends Function> q) { assert q != null; Function f = q.peek(); @@ -365,12 +367,12 @@ public class QueuePlugin<T extends QueuePlugin<?>> extends GQuery { data(elem, name, queue); } } - + private Callbacks emptyHooks(Element elem, String name) { String key = name + EMPTY_HOOKS; - Callbacks c = (Callbacks)data(elem, key, null); + Callbacks c = (Callbacks) data(elem, key, null); if (c == null) { - c = (Callbacks)data(elem, key, new Callbacks("once memory")); + c = (Callbacks) data(elem, key, new Callbacks("once memory")); } return c; } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/UiPlugin.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/UiPlugin.java index 0d85e1fb..92938d17 100755 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/UiPlugin.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/UiPlugin.java @@ -25,13 +25,13 @@ import com.google.gwt.query.client.Predicate; /** * GWT clone of jQueryUi-core. This class define some function present in the - * jQuery-ui core and not directly in jQuery + * jQuery-ui core and not directly in jQuery. * */ public class UiPlugin extends GQuery { /** - * A POJO used to store dimension of an element + * A POJO used to store dimension of an element. * */ public static class Dimension { @@ -56,7 +56,7 @@ public class UiPlugin extends GQuery { } /** - * return the width value + * return the width value. */ public int getWidth() { return width; @@ -76,14 +76,13 @@ public class UiPlugin extends GQuery { scrollParent = gQueryUi.parents().filter(new Predicate() { public boolean f(Element e, int index) { - GQuery $e = GQuery.$(e); - String position = $e.css("position", true); + GQuery g = GQuery.$(e); + String position = g.css("position", true); return ("relative".equals(position) || "absolute".equals(position) || "fixed" .equals(position)) - && isOverflowEnabled($e); + && isOverflowEnabled(g); } }); - } else { scrollParent = gQueryUi.parents().filter(new Predicate() { @@ -94,14 +93,13 @@ public class UiPlugin extends GQuery { } return scrollParent.length() > 0 ? $(scrollParent.get(0)) : $(getViewportElement()); - } protected boolean scrollParentPositionTest(UiPlugin gQueryUi) { return "absolute".equals(gQueryUi.css("position")); } - private final Element getViewportElement() { + private Element getViewportElement() { return GQuery.document.isCSS1Compat() ? GQuery.document .getDocumentElement() : GQuery.document.getBody(); } @@ -111,7 +109,6 @@ public class UiPlugin extends GQuery { + e.css("overflow-y", true); return overflow.contains("auto") || overflow.contains("scroll"); } - } @SuppressWarnings("unused") @@ -123,7 +120,6 @@ public class UiPlugin extends GQuery { return ("absolute".equals(position) || "relative".equals(position) || "static" .equals(position)); } - } public static Class<UiPlugin> GQueryUi = UiPlugin.class; @@ -150,7 +146,7 @@ public class UiPlugin extends GQuery { handlerManager.fireEvent(e); } if (callback != null) { - callback.f(element.<com.google.gwt.dom.client.Element>cast()); + callback.f(element.<com.google.gwt.dom.client.Element> cast()); } } @@ -162,7 +158,6 @@ public class UiPlugin extends GQuery { super(gq); } - /** * Return the immediate scrolling parent. */ @@ -177,5 +172,4 @@ public class UiPlugin extends GQuery { protected void trigger(GwtEvent<?> e, Function callback, Element element) { trigger(e, callback, element, eventBus); } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Widgets.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Widgets.java index 6367e7b7..0c26c0bc 100755 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Widgets.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Widgets.java @@ -15,9 +15,6 @@ */ package com.google.gwt.query.client.plugins; -import java.util.ArrayList; -import java.util.List; - import com.google.gwt.dom.client.Element; import com.google.gwt.query.client.GQuery; import com.google.gwt.query.client.plugins.widgets.ButtonWidgetFactory; @@ -36,6 +33,9 @@ import com.google.gwt.user.client.ui.TextArea; import com.google.gwt.user.client.ui.TextBox; import com.google.gwt.user.client.ui.Widget; +import java.util.ArrayList; +import java.util.List; + /** * Widgets plugin for Gwt Query. Be careful, this plugin is still experimental. * The api can change in next releases. @@ -62,7 +62,6 @@ public class Widgets extends QueuePlugin<Widgets> { super(gq); } - /** * Try to create a widget using the given factory and the given options for * each element of the query. Returns a new gquery set of elements with the @@ -85,7 +84,7 @@ public class Widgets extends QueuePlugin<Widgets> { } /** - * Create and return a widget using the given factory and the given options + * Create and return a widget using the given factory and the given options. */ protected <W extends Widget> W widget(Element e, WidgetFactory<W> factory, WidgetInitializer<W> initializer) { @@ -102,7 +101,7 @@ public class Widgets extends QueuePlugin<Widgets> { } /** - * Create and return a widget using the given factory and the given options + * Create and return a widget using the given factory and the given options. */ protected <W extends Widget> W widget(WidgetFactory<W> factory, WidgetInitializer<W> initializers) { @@ -139,7 +138,7 @@ public class Widgets extends QueuePlugin<Widgets> { public Widgets label() { return widgets(new LabelWidgetFactory(), null); } - + /** * Create a {@link Label} widget for each selected element. The * <code>initializers</code> will be called on each new {@link Label} created @@ -166,7 +165,6 @@ public class Widgets extends QueuePlugin<Widgets> { return widgets(new PasswordTextBoxWidgetFactory(), initializers); } - /** * Create a {@link TextBox} widget for each selected element. The * <code>initializers</code> will be called on each new {@link TextBox} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java index b0ee21ad..eb58f93d 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java @@ -1,3 +1,18 @@ +/* + * Copyright 2014, The gwtquery team. + * + * 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.gwt.query.client.plugins.ajax; import com.google.gwt.core.client.GWT; @@ -6,10 +21,10 @@ import com.google.gwt.core.client.ScriptInjector; import com.google.gwt.dom.client.Element; import com.google.gwt.http.client.Request; import com.google.gwt.http.client.Response; -import com.google.gwt.query.client.IsProperties; import com.google.gwt.query.client.Function; import com.google.gwt.query.client.GQ; import com.google.gwt.query.client.GQuery; +import com.google.gwt.query.client.IsProperties; import com.google.gwt.query.client.Promise; import com.google.gwt.query.client.builders.JsonBuilder; import com.google.gwt.query.client.js.JsUtils; @@ -35,46 +50,76 @@ public class Ajax extends GQuery { public static final String JSON_CONTENT_TYPE = "application/json"; public static final String JSON_CONTENT_TYPE_UTF8 = JSON_CONTENT_TYPE + "; charset=utf-8"; - - public static interface AjaxTransport { + + /** + * Ajax Transport object. + */ + public interface AjaxTransport { Promise getJsonP(Settings settings); Promise getLoadScript(Settings settings); Promise getXhr(Settings settings); } - + /** - * Ajax Settings object + * Ajax Settings object. */ public interface Settings extends JsonBuilder { String getContentType(); + Element getContext(); + IsProperties getData(); + String getDataString(); + String getDataType(); + Function getError(); + IsProperties getHeaders(); + String getPassword(); + Function getSuccess(); + int getTimeout(); + String getType(); + String getUrl(); + String getUsername(); + boolean getWithCredentials(); + Settings setContentType(String t); + Settings setContext(Element e); + Settings setData(Object p); + Settings setDataString(String d); + Settings setDataType(String t); + Settings setError(Function f); + Settings setHeaders(IsProperties p); + Settings setPassword(String p); + Settings setSuccess(Function f); + Settings setTimeout(int t); + Settings setType(String t); + Settings setUrl(String u); + Settings setUsername(String u); + Settings setWithCredentials(boolean b); } @@ -93,7 +138,6 @@ public class Ajax extends GQuery { /** * Perform an ajax request to the server. * - * * Example: * * <pre> @@ -112,14 +156,10 @@ public class Ajax extends GQuery { }, properties); * </pre> * - * @param url The url to connect - * @param onSuccess a function to execute in the case of success - * @param onError the function to execute on error - * @param settings a Properties object with the configuration of the Ajax request. */ public static Promise ajax(Settings settings) { resolveSettings(settings); - + final Function onSuccess = settings.getSuccess(); if (onSuccess != null) { onSuccess.setElement(settings.getContext()); @@ -136,45 +176,45 @@ public class Ajax extends GQuery { if ("jsonp".equalsIgnoreCase(dataType)) { ret = GQ.getAjaxTransport().getJsonP(settings); - } else if ("loadscript".equalsIgnoreCase(dataType)){ + } else if ("loadscript".equalsIgnoreCase(dataType)) { ret = GQ.getAjaxTransport().getLoadScript(settings); } else { ret = GQ.getAjaxTransport().getXhr(settings) - .then(new Function() { - public Object f(Object...args) { - Response response = arguments(0); - Request request = arguments(1); - Object retData = response.getText(); - if (retData != null && !"".equals(retData)) { - try { - if ("xml".equalsIgnoreCase(dataType)) { - retData = JsUtils.parseXML(response.getText()); - } else if ("json".equalsIgnoreCase(dataType)) { - retData = GQ.create(response.getText()); - } else { - retData = response.getText(); - if ("script".equalsIgnoreCase(dataType)) { - ScriptInjector.fromString((String)retData).setWindow(window).inject(); + .then(new Function() { + public Object f(Object... args) { + Response response = arguments(0); + Request request = arguments(1); + Object retData = response.getText(); + if (retData != null && !"".equals(retData)) { + try { + if ("xml".equalsIgnoreCase(dataType)) { + retData = JsUtils.parseXML(response.getText()); + } else if ("json".equalsIgnoreCase(dataType)) { + retData = GQ.create(response.getText()); + } else { + retData = response.getText(); + if ("script".equalsIgnoreCase(dataType)) { + ScriptInjector.fromString((String) retData).setWindow(window).inject(); + } + } + } catch (Exception e) { + if (GWT.isClient() && GWT.getUncaughtExceptionHandler() != null) { + GWT.getUncaughtExceptionHandler().onUncaughtException(e); + } else { + e.printStackTrace(); } - } - } catch (Exception e) { - if (GWT.isClient() && GWT.getUncaughtExceptionHandler() != null) { - GWT.getUncaughtExceptionHandler().onUncaughtException(e); - } else { - e.printStackTrace(); } } + return new Object[] {retData, "success", request, response}; } - return new Object[]{retData, "success", request, response}; - } - }, new Function() { - public Object f(Object...args) { - Throwable exception = arguments(0); - Request request = getArgument(1, Request.class); - String msg = String.valueOf(exception); - return new Object[]{null, msg, request, null, exception}; - } - }); + }, new Function() { + public Object f(Object... args) { + Throwable exception = arguments(0); + Request request = getArgument(1, Request.class); + String msg = String.valueOf(exception); + return new Object[] {null, msg, request, null, exception}; + } + }); } if (onSuccess != null) { ret.done(onSuccess); @@ -184,11 +224,11 @@ public class Ajax extends GQuery { } return ret; } - + private static void resolveSettings(Settings settings) { String url = settings.getUrl(); - assert settings != null && settings.getUrl() != null: "no url found in settings"; - + assert settings != null && settings.getUrl() != null : "no url found in settings"; + String type = "POST"; if (settings.getType() != null) { type = settings.getType().toUpperCase(); @@ -201,10 +241,12 @@ public class Ajax extends GQuery { IsProperties data = settings.getData(); if (data != null) { String dataString = null, contentType = null; - if (data.getDataImpl() instanceof JavaScriptObject && JsUtils.isFormData(data.<JavaScriptObject>getDataImpl())) { + if (data.getDataImpl() instanceof JavaScriptObject + && JsUtils.isFormData(data.<JavaScriptObject> getDataImpl())) { dataString = null; contentType = FormPanel.ENCODING_URLENCODED; - } else if (settings.getType().matches("(POST|PUT)") && "json".equalsIgnoreCase(settings.getDataType())) { + } else if (settings.getType().matches("(POST|PUT)") + && "json".equalsIgnoreCase(settings.getDataType())) { dataString = data.toJson(); contentType = JSON_CONTENT_TYPE_UTF8; } else { @@ -220,7 +262,7 @@ public class Ajax extends GQuery { settings.setUrl(url); } } - + public static Promise ajax(String url, Function onSuccess, Function onError) { return ajax(url, onSuccess, onError, (Settings) null); } @@ -250,7 +292,7 @@ public class Ajax extends GQuery { public static Settings createSettings(String prop) { Settings s = GQ.create(Settings.class); - if (prop != null && !prop.isEmpty()) + if (prop != null && !prop.isEmpty()) s.parse(prop); return s; } @@ -266,7 +308,7 @@ public class Ajax extends GQuery { } public static Promise get(String url, IsProperties data) { - return get(url, (IsProperties)data, null); + return get(url, (IsProperties) data, null); } public static Promise get(String url, IsProperties data, Function onSuccess) { @@ -298,7 +340,7 @@ public class Ajax extends GQuery { } public static Promise getJSONP(String url, IsProperties data) { - return getJSONP(url, (IsProperties)data, null); + return getJSONP(url, (IsProperties) data, null); } public static Promise getJSONP(String url, IsProperties data, Function onSuccess) { @@ -313,13 +355,12 @@ public class Ajax extends GQuery { public static Promise getJSONP(String url, Function success, Function error, int timeout) { return ajax(createSettings() - .setUrl(url) - .setDataType("jsonp") - .setType("get") - .setTimeout(timeout) - .setSuccess(success) - .setError(error) - ); + .setUrl(url) + .setDataType("jsonp") + .setType("get") + .setTimeout(timeout) + .setSuccess(success) + .setError(error)); } /** @@ -331,15 +372,14 @@ public class Ajax extends GQuery { public static Promise getScript(final String url, Function success) { return ajax(createSettings() - .setUrl(url) - .setType("get") - .setDataType("script") - .setSuccess(success) - ); + .setUrl(url) + .setType("get") + .setDataType("script") + .setSuccess(success)); } /** - * Load a JavaScript file from any url using the script tag mechanism + * Load a JavaScript file from any url using the script tag mechanism. */ public static Promise loadScript(String url) { return loadScript(url, null); @@ -347,15 +387,14 @@ public class Ajax extends GQuery { public static Promise loadScript(final String url, Function success) { return ajax(createSettings() - .setUrl(url) - .setType("get") - .setDataType("loadscript") - .setSuccess(success) - ); + .setUrl(url) + .setType("get") + .setDataType("loadscript") + .setSuccess(success)); } public static Promise post(String url, IsProperties data) { - return post(url, (IsProperties)data, null); + return post(url, (IsProperties) data, null); } public static Promise post(String url, IsProperties data, final Function onSuccess) { @@ -375,7 +414,7 @@ public class Ajax extends GQuery { public Ajax load(String url, IsProperties data) { return load(url, data); } - + public Ajax load(String url, IsProperties data, final Function onSuccess) { Settings s = createSettings(); final String filter = url.contains(" ") ? url.replaceFirst("^[^\\s]+\\s+", "") : ""; @@ -391,10 +430,10 @@ public class Ajax extends GQuery { // not support java embedded flag expressions (?s) and javascript does // not have multidot flag. String s = arguments(0).toString().replaceAll("<![^>]+>\\s*", "") - .replaceAll("</?html[\\s\\S]*?>\\s*", "") - .replaceAll("<head[\\s\\S]*?</head>\\s*", "") - .replaceAll("<script[\\s\\S]*?</script>\\s*", "") - .replaceAll("</?body[\\s\\S]*?>\\s*", ""); + .replaceAll("</?html[\\s\\S]*?>\\s*", "") + .replaceAll("<head[\\s\\S]*?</head>\\s*", "") + .replaceAll("<script[\\s\\S]*?</script>\\s*", "") + .replaceAll("</?body[\\s\\S]*?>\\s*", ""); // We wrap the results in a div s = "<div>" + s + "</div>"; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/AjaxTransportJs.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/AjaxTransportJs.java index 12ce7cda..15406a68 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/AjaxTransportJs.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/AjaxTransportJs.java @@ -1,3 +1,18 @@ +/* + * Copyright 2014, The gwtquery team. + * + * 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.gwt.query.client.plugins.ajax; import com.google.gwt.core.client.Callback; @@ -16,30 +31,32 @@ import com.google.gwt.query.client.plugins.deferred.PromiseReqBuilderJSONP; * Ajax transport for Client side. */ public class AjaxTransportJs implements AjaxTransport { - + @Override public Promise getJsonP(Settings settings) { return new PromiseReqBuilderJSONP(settings.getUrl(), settings.getTimeout()); } - + @Override public Promise getLoadScript(final Settings settings) { return new PromiseFunction() { private ScriptElement scriptElement; + public void f(final Deferred dfd) { scriptElement = ScriptInjector.fromUrl(settings.getUrl()).setWindow(GQuery.window) - .setCallback(new Callback<Void, Exception>() { - public void onSuccess(Void result) { - GQuery.$(GQuery.window).delay(0, new Function(){ - public void f() { - dfd.resolve(scriptElement); + .setCallback(new Callback<Void, Exception>() { + public void onSuccess(Void result) { + GQuery.$(GQuery.window).delay(0, new Function() { + public void f() { + dfd.resolve(scriptElement); + } + }); + } + + public void onFailure(Exception reason) { + dfd.reject(reason); } - }); - } - public void onFailure(Exception reason) { - dfd.reject(reason); - } - }).inject().cast(); + }).inject().cast(); } }; } @@ -47,5 +64,4 @@ public class AjaxTransportJs implements AjaxTransport { public Promise getXhr(Settings settings) { return new PromiseReqBuilder(settings); } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/Callbacks.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/Callbacks.java index 462ccad8..508c82e5 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/Callbacks.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/Callbacks.java @@ -13,41 +13,40 @@ */ package com.google.gwt.query.client.plugins.deferred; +import com.google.gwt.query.client.Function; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import com.google.gwt.query.client.Function; - /** * Implementation of jQuery.Callbacks for gwtquery. */ public class Callbacks { - + /** - * Iterface used for callbacks which could cancel the execution - * when returning false; - * + * Iterface used for callbacks which could cancel the execution + * when returning false. */ - public static interface Callback { + public interface Callback { /** - * Return false to avoid executing the rest of functions + * Return false to avoid executing the rest of functions. */ - boolean f(Object ...objects); + boolean f(Object... objects); } - + private List<Object> stack = new ArrayList<Object>(); - + private boolean done = false; - + private List<Object> memory = null; - + private boolean isOnce, isMemory, isUnique, stopOnFalse; - + public Callbacks() { this(""); } - + /** * Create a new Callbacks object with options given as a space delimited string. * @@ -61,21 +60,21 @@ public class Callbacks { isUnique = options.contains("unique"); stopOnFalse = options.contains("stopOnFalse"); } - + /** * Add a Callback or a collection of callbacks to a callback list. * */ public Callbacks add(Callback... c) { - addAll((Object[])c); + addAll((Object[]) c); return this; } - + /** * Add a Callback or a collection of callbacks to a callback list. */ public Callbacks add(com.google.gwt.core.client.Callback<?, ?>... c) { - addAll((Object[])c); + addAll((Object[]) c); return this; } @@ -83,10 +82,10 @@ public class Callbacks { * Add a Function or a collection of Function to a callback list. */ public Callbacks add(Function... f) { - addAll((Object[])f); + addAll((Object[]) f); return this; } - + /** * Disable a callback list from doing anything more. */ @@ -95,9 +94,9 @@ public class Callbacks { done = true; return this; } - + /** - * lock + * lock. */ public Callbacks lock() { if (!isMemory) { @@ -116,15 +115,16 @@ public class Callbacks { if (isMemory) { memory = new ArrayList<Object>(Arrays.asList(o)); } - if (stack != null) for (Object c : stack) { - if (!run(c, o) && stopOnFalse) { - break; + if (stack != null) + for (Object c : stack) { + if (!run(c, o) && stopOnFalse) { + break; + } } - } } return this; } - + /** * Remove a callback or a collection of callbacks from a callback list. */ @@ -132,8 +132,8 @@ public class Callbacks { stack.removeAll(Arrays.asList(o)); return this; } - - private void addAll(Object...o) { + + private void addAll(Object... o) { for (Object c : o) { if (!done && stack != null && c != null && (!isUnique || !stack.contains(c))) { stack.add(c); @@ -143,28 +143,27 @@ public class Callbacks { run(c, memory.toArray()); } } - } + } @SuppressWarnings({"unchecked", "rawtypes"}) - private boolean run(Object c, Object...o) { + private boolean run(Object c, Object... o) { // Unbox array inside array when there is only an element. // It happens when running filters in Promise.then() if (o != null && o.length == 1 && o[0] != null && o[0].getClass().isArray()) { - o = (Object[])o[0]; + o = (Object[]) o[0]; } if (c instanceof Callback) { - return ((Callback)c).f(o); + return ((Callback) c).f(o); } else if (c instanceof Function) { - Object r = ((Function)c).f(o); - return (r instanceof Boolean) ? (Boolean)r : true; + Object r = ((Function) c).f(o); + return (r instanceof Boolean) ? (Boolean) r : true; } else if (c instanceof com.google.gwt.core.client.Callback) { - ((com.google.gwt.core.client.Callback)c).onSuccess(o); + ((com.google.gwt.core.client.Callback) c).onSuccess(o); } return true; } - + public String status() { return "stack=" + (stack == null ? "null" : stack.size()) + " " + done; } } - diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/Deferred.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/Deferred.java index 91c899a5..9cb7b624 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/Deferred.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/Deferred.java @@ -15,7 +15,9 @@ */ package com.google.gwt.query.client.plugins.deferred; -import static com.google.gwt.query.client.Promise.*; +import static com.google.gwt.query.client.Promise.PENDING; +import static com.google.gwt.query.client.Promise.REJECTED; +import static com.google.gwt.query.client.Promise.RESOLVED; import com.google.gwt.query.client.Function; import com.google.gwt.query.client.GQuery; @@ -46,7 +48,8 @@ public class Deferred implements Promise.Deferred { // Whether break the flow if old deferred fails boolean cont = false; - public ThenFunction(Deferred newDfd, Function[] subordinates, int funcType, boolean continueFlow) { + public ThenFunction(Deferred newDfd, Function[] subordinates, int funcType, + boolean continueFlow) { type = funcType; filter = subordinates.length > type ? subordinates[type] : null; dfd = newDfd; @@ -63,18 +66,23 @@ public class Deferred implements Promise.Deferred { // If filter function returns a promise we pipeline it. final Promise p = (Promise) newArgs; if (type == PROGRESS) { - p.progress(new Function(){public void f() { - settle(PROGRESS, getArguments()); - }}); + p.progress(new Function() { + public void f() { + settle(PROGRESS, getArguments()); + } + }); } else { - p.always(new Function(){public void f() { - settle((type == DONE || type == FAIL && cont) && p.isResolved() ? DONE : FAIL, getArguments()); - }}); + p.always(new Function() { + public void f() { + settle((type == DONE || type == FAIL && cont) && p.isResolved() ? DONE : FAIL, + getArguments()); + } + }); } } else { // Otherwise we change the arguments by the new ones newArgs = Boolean.TRUE.equals(newArgs) ? oldArgs : - newArgs != null && newArgs.getClass().isArray() ? (Object[])newArgs : newArgs; + newArgs != null && newArgs.getClass().isArray() ? (Object[]) newArgs : newArgs; settle(type, newArgs); } } else { @@ -84,9 +92,12 @@ public class Deferred implements Promise.Deferred { } private void settle(int action, Object... args) { - if (action == DONE) dfd.resolve(args); - if (action == FAIL) dfd.reject(args); - if (action == PROGRESS) dfd.notify(args); + if (action == DONE) + dfd.resolve(args); + if (action == FAIL) + dfd.reject(args); + if (action == PROGRESS) + dfd.notify(args); } } @@ -276,11 +287,11 @@ public class Deferred implements Promise.Deferred { private static Promise makePromise(final Object o) { if (o instanceof Promise) { - return (Promise)o; + return (Promise) o; } else if (o instanceof Function) { - return makePromise(((Function)o).f(new Object[0])); + return makePromise(((Function) o).f(new Object[0])); } else if (o instanceof GQuery) { - return ((GQuery)o).promise(); + return ((GQuery) o).promise(); } else { return new PromiseFunction() { public void f(Deferred dfd) { @@ -334,7 +345,8 @@ public class Deferred implements Promise.Deferred { * Call the progressCallbacks on a Deferred object with the given args. */ public Deferred notify(Object... o) { - if (state == PENDING) notify.fire(o); + if (state == PENDING) + notify.fire(o); return this; } @@ -352,7 +364,8 @@ public class Deferred implements Promise.Deferred { * Reject a Deferred object and call any failCallbacks with the given args. */ public Deferred reject(Object... o) { - if (state == PENDING) reject.fire(o); + if (state == PENDING) + reject.fire(o); return this; } @@ -360,12 +373,14 @@ public class Deferred implements Promise.Deferred { * Resolve a Deferred object and call any doneCallbacks with the given args. */ public Deferred resolve(Object... o) { - if (state == PENDING) resolve.fire(o); + if (state == PENDING) + resolve.fire(o); return this; } @Override public String toString() { - return "Deferred this=" + hashCode() + " promise=" + promise().hashCode() + " state=" + promise.state() + " restatus=" + resolve.status(); + return "Deferred this=" + hashCode() + " promise=" + promise().hashCode() + " state=" + + promise.state() + " restatus=" + resolve.status(); } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/FunctionDeferred.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/FunctionDeferred.java index 771749f8..25295e46 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/FunctionDeferred.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/FunctionDeferred.java @@ -17,7 +17,7 @@ import com.google.gwt.query.client.Function; import com.google.gwt.query.client.Promise.Deferred; /** - * Utility class used to create customized functions with a deferred + * Utility class used to create customized functions with a deferred * execution in pipelined processes. * * They have access to the associated deferred object via a method which @@ -45,7 +45,12 @@ import com.google.gwt.query.client.Promise.Deferred; */ public abstract class FunctionDeferred extends Function { - public static enum CacheType {NONE, ALL, RESOLVED, REJECTED}; + /** + * Cache types. + */ + public static enum CacheType { + NONE, ALL, RESOLVED, REJECTED + }; protected Deferred dfd; public Function resolve, reject; @@ -61,13 +66,13 @@ public abstract class FunctionDeferred extends Function { /** * This function is called when the previous promise in the pipe - * is resolved. + * is resolved. */ public final Object f(Object... args) { - return dfd != null && + return dfd != null && (cache == CacheType.ALL || - cache == CacheType.RESOLVED && dfd.promise().isResolved() || - cache == CacheType.REJECTED && dfd.promise().isRejected()) + cache == CacheType.RESOLVED && dfd.promise().isResolved() || + cache == CacheType.REJECTED && dfd.promise().isRejected()) ? dfd.promise() : new PromiseFunction() { public void f(Deferred dfd) { @@ -76,7 +81,7 @@ public abstract class FunctionDeferred extends Function { FunctionDeferred.this.dfd = dfd; FunctionDeferred.this.f(dfd); } - }; + }; } /** @@ -89,7 +94,7 @@ public abstract class FunctionDeferred extends Function { cache = type; return this; } - + /** * Reset the cache so as a new invocation to this function will * execute it instead of restoring old values from cache. diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseFunction.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseFunction.java index 996992e7..5ca5c154 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseFunction.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseFunction.java @@ -26,7 +26,7 @@ import com.google.gwt.query.client.plugins.deferred.Deferred.DeferredPromiseImpl * dfd.resolve("done"); * } * }; - * + * * doSomething.progress(new Function() { * public void f() { * String hi = arguments(0); @@ -42,7 +42,7 @@ public abstract class PromiseFunction extends DeferredPromiseImpl { public PromiseFunction() { f(dfd); } - + /** * This function is called once when the promise is created and the * new deferred is available. diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseRPC.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseRPC.java index 2785e17f..b108f56e 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseRPC.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseRPC.java @@ -20,10 +20,10 @@ import com.google.gwt.user.client.rpc.AsyncCallback; * Utility class used to create promises for RPC services. * <pre> * PromiseRPC<String> greeting = new PromiseRPC<String>(); - * + * * GreetingServiceAsync greetingService = GWT.create(GreetingService.class); * greetingService.greetServer("hi", greeting); - * + * * greeting.fail(new Function(){ * public void f() { * Throwable error = arguments(0); @@ -34,6 +34,8 @@ import com.google.gwt.user.client.rpc.AsyncCallback; * } * }); * </pre> + * + * @param <T> */ public class PromiseRPC<T> extends DeferredPromiseImpl implements AsyncCallback<T> { public void onFailure(Throwable caught) { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseReqBuilder.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseReqBuilder.java index 41f32b37..af9b9641 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseReqBuilder.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseReqBuilder.java @@ -1,3 +1,18 @@ +/* + * Copyright 2014, The gwtquery team. + * + * 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.gwt.query.client.plugins.deferred; /* @@ -21,8 +36,8 @@ import com.google.gwt.http.client.RequestCallback; import com.google.gwt.http.client.RequestException; import com.google.gwt.http.client.RequestPermissionException; import com.google.gwt.http.client.Response; -import com.google.gwt.query.client.IsProperties; import com.google.gwt.query.client.Function; +import com.google.gwt.query.client.IsProperties; import com.google.gwt.query.client.js.JsCache; import com.google.gwt.query.client.js.JsUtils; import com.google.gwt.query.client.plugins.ajax.Ajax.Settings; @@ -61,14 +76,16 @@ public class PromiseReqBuilder extends DeferredPromiseImpl implements RequestCal /** * Using this constructor we access to some things in the xmlHttpRequest * which are not available in GWT, like adding progress handles or sending - * javascript data (like forms in modern html5 file api) + * javascript data (like forms in modern html5 file api). */ public PromiseReqBuilder(Settings settings) { String httpMethod = settings.getType(); String url = settings.getUrl(); IsProperties data = settings.getData(); String ctype = settings.getContentType(); - Boolean isFormData = data != null && data.getDataImpl() instanceof JavaScriptObject && JsUtils.isFormData(data.<JavaScriptObject>getDataImpl()); + Boolean isFormData = + data != null && data.getDataImpl() instanceof JavaScriptObject + && JsUtils.isFormData(data.<JavaScriptObject> getDataImpl()); XMLHttpRequest xmlHttpRequest = XMLHttpRequest.create(); try { @@ -134,7 +151,8 @@ public class PromiseReqBuilder extends DeferredPromiseImpl implements RequestCal }); try { - JsUtils.runJavascriptFunction(xmlHttpRequest, "send", isFormData ? data.getDataImpl() : settings.getDataString()); + JsUtils.runJavascriptFunction(xmlHttpRequest, "send", isFormData ? data.getDataImpl() + : settings.getDataString()); } catch (JavaScriptException e) { onError(null, e); } @@ -148,21 +166,22 @@ public class PromiseReqBuilder extends DeferredPromiseImpl implements RequestCal int status = response.getStatusCode(); if (status <= 0 || status >= 400) { String statusText = status <= 0 ? "Bad CORS" : response.getStatusText(); - onError(request, new RequestException("HTTP ERROR: " + status + " " + statusText + "\n" + response.getText())); + onError(request, new RequestException("HTTP ERROR: " + status + " " + statusText + "\n" + + response.getText())); } else { dfd.resolve(response, request); } } /** - * Using violator pattern to execute private method + * Using violator pattern to execute private method. */ private native void fireOnResponseReceivedVltr(Request rq, RequestCallback cb) /*-{ rq.@com.google.gwt.http.client.Request::fireOnResponseReceived(Lcom/google/gwt/http/client/RequestCallback;)(cb); }-*/; /** - * Using violator pattern to use protected constructor + * Using violator pattern to use protected constructor. */ private native Request createRequestVltr(XMLHttpRequest rq, int ms, RequestCallback cb) /*-{ return @com.google.gwt.http.client.Request::new(Lcom/google/gwt/xhr/client/XMLHttpRequest;ILcom/google/gwt/http/client/RequestCallback;)(rq,ms,cb); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseReqBuilderJSONP.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseReqBuilderJSONP.java index 9278bf7b..0935fb2f 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseReqBuilderJSONP.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseReqBuilderJSONP.java @@ -23,7 +23,7 @@ import com.google.gwt.user.client.rpc.AsyncCallback; * Utility class used to create promises for JsonpRequestBuilder. * <pre> * Promise p = new PromiseJsonpReqBuilder(url, 4000); - * + * * p.done(new Function() { * public void f() { * Properties p = arguments(0); @@ -36,9 +36,9 @@ import com.google.gwt.user.client.rpc.AsyncCallback; * </pre> */ public class PromiseReqBuilderJSONP extends DeferredPromiseImpl { - + private static final RegExp callbackRegex = RegExp.compile("^(.+[\\?&])([^=]+)=\\?(.*)$"); - + public PromiseReqBuilderJSONP(String url) { this(url, null, 0); } @@ -55,7 +55,7 @@ public class PromiseReqBuilderJSONP extends DeferredPromiseImpl { // jQuery allows a parameter callback=? to figure out the callback parameter if (callbackParam == null) { MatchResult tmp = callbackRegex.exec(url); - if (tmp != null && tmp.getGroupCount() == 4) { + if (tmp != null && tmp.getGroupCount() == 4) { callbackParam = tmp.getGroup(2); url = tmp.getGroup(1) + tmp.getGroup(3); } @@ -75,7 +75,7 @@ public class PromiseReqBuilderJSONP extends DeferredPromiseImpl { } // Using jsni because method send in JsonpRequestBuilder is private - private final native void send(JsonpRequestBuilder bld, String url, AsyncCallback<?> cb) /*-{ + private native void send(JsonpRequestBuilder bld, String url, AsyncCallback<?> cb) /*-{ bld.@com.google.gwt.jsonp.client.JsonpRequestBuilder::send(Ljava/lang/String;Lcom/google/gwt/user/client/rpc/AsyncCallback;Z)(url,cb,false); }-*/; } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/Bezier.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/Bezier.java index 147f94ca..d167979e 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/Bezier.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/Bezier.java @@ -25,46 +25,52 @@ package com.google.gwt.query.client.plugins.effects; * [2] http://dxr.mozilla.org/mozilla-central/source/content/smil/nsSMILKeySpline.cpp */ public class Bezier { - - private double x1, y1 , x2, y2; - + + private double x1, y1, x2, y2; + public Bezier(double x1, double y1, double x2, double y2) { - this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2; + this.x1 = x1; + this.y1 = y1; + this.x2 = x2; + this.y2 = y2; } - + private double a(double a1, double a2) { return 1.0 - 3.0 * a2 + 3.0 * a1; } + private double b(double a1, double a2) { return 3.0 * a2 - 6.0 * a1; } - private double c(double a1){ + + private double c(double a1) { return 3.0 * a1; } - + private double calcBezier(double t, double a1, double a2) { - return ((a(a1, a2)*t + b(a1, a2))*t + c(a1))*t; + return ((a(a1, a2) * t + b(a1, a2)) * t + c(a1)) * t; } - + private double calcSlope(double t, double a1, double a2) { - return 3.0 * a(a1, a2)*t*t + 2.0 * b(a1, a2) * t + c(a1); + return 3.0 * a(a1, a2) * t * t + 2.0 * b(a1, a2) * t + c(a1); } - + private double getTForX(double x) { double t = x; for (double i = 0; i < 4; ++i) { double currentSlope = calcSlope(t, x1, x2); - if (currentSlope == 0.0) return t; + if (currentSlope == 0.0) + return t; double currentX = calcBezier(t, x1, x2) - x; t -= currentX / currentSlope; } return t; } - - public double f (double x) { + + public double f(double x) { return calcBezier(getTForX(x), y1, y2); } - + public String toString() { return x1 + "," + y1 + "," + x2 + "," + y2; } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/ClipAnimation.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/ClipAnimation.java index deead04d..627c0b47 100755 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/ClipAnimation.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/ClipAnimation.java @@ -48,8 +48,8 @@ public class ClipAnimation extends PropertiesAnimation { BIDIRECTIONAL, HORIZONTAL, VERTICAL } - private static final String[] attrsToSave = new String[]{ - "position", "overflow", "visibility", "white-space", "top", "left", "width", "height"}; + private static final String[] attrsToSave = new String[] { + "position", "overflow", "visibility", "white-space", "top", "left", "width", "height"}; private Action action; private Corner corner; @@ -120,7 +120,7 @@ public class ClipAnimation extends PropertiesAnimation { if (action == null) { return; } - currentAction = action != Action.TOGGLE ? action : hidden ? Action.SHOW : Action.HIDE; + currentAction = action != Action.TOGGLE ? action : hidden ? Action.SHOW : Action.HIDE; g.saveCssAttrs(attrsToSave); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/Fx.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/Fx.java index e497d8f3..b81a9de9 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/Fx.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/Fx.java @@ -1,3 +1,18 @@ +/* + * Copyright 2014, The gwtquery team. + * + * 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.gwt.query.client.plugins.effects; import com.google.gwt.dom.client.Element; @@ -14,7 +29,7 @@ import com.google.gwt.regexp.shared.RegExp; public class Fx { /** - * Public variable to enable/disable effects + * Public variable to enable/disable effects. */ public static boolean off = false; @@ -39,7 +54,7 @@ public class Fx { } public String toString() { - return super.toString() + " transitStart=" + transitStart + " transitEnd=" + transitEnd; + return super.toString() + " transitStart=" + transitStart + " transitEnd=" + transitEnd; } } @@ -49,7 +64,7 @@ public class Fx { public static class ColorFx extends Fx { /** - * Specific class handle specific borderColor shortcut properties + * Specific class handle specific borderColor shortcut properties. */ public static class BorderColorFx extends ColorFx { @@ -66,10 +81,10 @@ public class Fx { endColor = parseColor(endColorString); startColors = JsNamedArray.create(); - GQuery $e = GQuery.$(e); + GQuery g = GQuery.$(e); for (String border : borderColorProperties) { - int[] startColor = parseColor($e.css(border, true)); + int[] startColor = parseColor(g.css(border, true)); startColors.put(border, startColor); } } @@ -85,60 +100,62 @@ public class Fx { } // hexadecimal regex - public static RegExp REGEX_HEX_COLOR_PATTERN = RegExp.compile("#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})"); + public static RegExp REGEX_HEX_COLOR_PATTERN = RegExp + .compile("#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})"); private static JsNamedArray<int[]> htmlColorToRgb; // rgb and rgba regex - public static RegExp REGEX_RGB_COLOR_PATTERN = - RegExp.compile("rgba?\\(\\s*([0-9]{1,3}%?)\\s*,\\s*([0-9]{1,3}%?)\\s*,\\s*([0-9]{1,3}%?).*\\)$"); + public static RegExp REGEX_RGB_COLOR_PATTERN = + RegExp + .compile("rgba?\\(\\s*([0-9]{1,3}%?)\\s*,\\s*([0-9]{1,3}%?)\\s*,\\s*([0-9]{1,3}%?).*\\)$"); static { htmlColorToRgb = JsNamedArray.create(); - htmlColorToRgb.put("white", new int[]{255, 255, 255}); - htmlColorToRgb.put("aqua", new int[]{0, 255, 255}); - htmlColorToRgb.put("azure", new int[]{240, 255, 255}); - htmlColorToRgb.put("beige", new int[]{245, 245, 220}); - htmlColorToRgb.put("black", new int[]{0, 0, 0}); - htmlColorToRgb.put("blue", new int[]{0, 0, 255}); - htmlColorToRgb.put("brown", new int[]{165, 42, 42}); - htmlColorToRgb.put("cyan", new int[]{0, 255, 255}); - htmlColorToRgb.put("darkblue", new int[]{0, 0, 139}); - htmlColorToRgb.put("darkcyan", new int[]{0, 139, 139}); - htmlColorToRgb.put("darkgrey", new int[]{169, 169, 169}); - htmlColorToRgb.put("darkgreen", new int[]{0, 100, 0}); - htmlColorToRgb.put("darkkhaki", new int[]{189, 183, 107}); - htmlColorToRgb.put("darkmagenta", new int[]{139, 0, 139}); - htmlColorToRgb.put("darkolivegreen", new int[]{85, 107, 47}); - htmlColorToRgb.put("darkorange", new int[]{255, 140, 0}); - htmlColorToRgb.put("darkorchid", new int[]{153, 50, 204}); - htmlColorToRgb.put("darkred", new int[]{139, 0, 0}); - htmlColorToRgb.put("darksalmon", new int[]{233, 150, 122}); - htmlColorToRgb.put("darkviolet", new int[]{148, 0, 211}); - htmlColorToRgb.put("fuchsia", new int[]{255, 0, 255}); - htmlColorToRgb.put("gold", new int[]{255, 215, 0}); - htmlColorToRgb.put("green", new int[]{0, 128, 0}); - htmlColorToRgb.put("indigo", new int[]{75, 0, 130}); - htmlColorToRgb.put("khaki", new int[]{240, 230, 140}); - htmlColorToRgb.put("lightblue", new int[]{173, 216, 230}); - htmlColorToRgb.put("lightcyan", new int[]{224, 255, 255}); - htmlColorToRgb.put("lightgreen", new int[]{144, 238, 144}); - htmlColorToRgb.put("lightgrey", new int[]{211, 211, 211}); - htmlColorToRgb.put("lightpink", new int[]{255, 182, 193}); - htmlColorToRgb.put("lightyellow", new int[]{255, 255, 224}); - htmlColorToRgb.put("lime", new int[]{0, 255, 0}); - htmlColorToRgb.put("magenta", new int[]{255, 0, 255}); - htmlColorToRgb.put("maroon", new int[]{128, 0, 0}); - htmlColorToRgb.put("navy", new int[]{0, 0, 128}); - htmlColorToRgb.put("olive", new int[]{128, 128, 0}); - htmlColorToRgb.put("orange", new int[]{255, 165, 0}); - htmlColorToRgb.put("pink", new int[]{255, 192, 203}); - htmlColorToRgb.put("purple", new int[]{128, 0, 128}); - htmlColorToRgb.put("violet", new int[]{128, 0, 128}); - htmlColorToRgb.put("red", new int[]{255, 0, 0}); - htmlColorToRgb.put("silver", new int[]{192, 192, 192}); - htmlColorToRgb.put("white", new int[]{255, 255, 255}); - htmlColorToRgb.put("yellow", new int[]{255, 255, 0}); + htmlColorToRgb.put("white", new int[] {255, 255, 255}); + htmlColorToRgb.put("aqua", new int[] {0, 255, 255}); + htmlColorToRgb.put("azure", new int[] {240, 255, 255}); + htmlColorToRgb.put("beige", new int[] {245, 245, 220}); + htmlColorToRgb.put("black", new int[] {0, 0, 0}); + htmlColorToRgb.put("blue", new int[] {0, 0, 255}); + htmlColorToRgb.put("brown", new int[] {165, 42, 42}); + htmlColorToRgb.put("cyan", new int[] {0, 255, 255}); + htmlColorToRgb.put("darkblue", new int[] {0, 0, 139}); + htmlColorToRgb.put("darkcyan", new int[] {0, 139, 139}); + htmlColorToRgb.put("darkgrey", new int[] {169, 169, 169}); + htmlColorToRgb.put("darkgreen", new int[] {0, 100, 0}); + htmlColorToRgb.put("darkkhaki", new int[] {189, 183, 107}); + htmlColorToRgb.put("darkmagenta", new int[] {139, 0, 139}); + htmlColorToRgb.put("darkolivegreen", new int[] {85, 107, 47}); + htmlColorToRgb.put("darkorange", new int[] {255, 140, 0}); + htmlColorToRgb.put("darkorchid", new int[] {153, 50, 204}); + htmlColorToRgb.put("darkred", new int[] {139, 0, 0}); + htmlColorToRgb.put("darksalmon", new int[] {233, 150, 122}); + htmlColorToRgb.put("darkviolet", new int[] {148, 0, 211}); + htmlColorToRgb.put("fuchsia", new int[] {255, 0, 255}); + htmlColorToRgb.put("gold", new int[] {255, 215, 0}); + htmlColorToRgb.put("green", new int[] {0, 128, 0}); + htmlColorToRgb.put("indigo", new int[] {75, 0, 130}); + htmlColorToRgb.put("khaki", new int[] {240, 230, 140}); + htmlColorToRgb.put("lightblue", new int[] {173, 216, 230}); + htmlColorToRgb.put("lightcyan", new int[] {224, 255, 255}); + htmlColorToRgb.put("lightgreen", new int[] {144, 238, 144}); + htmlColorToRgb.put("lightgrey", new int[] {211, 211, 211}); + htmlColorToRgb.put("lightpink", new int[] {255, 182, 193}); + htmlColorToRgb.put("lightyellow", new int[] {255, 255, 224}); + htmlColorToRgb.put("lime", new int[] {0, 255, 0}); + htmlColorToRgb.put("magenta", new int[] {255, 0, 255}); + htmlColorToRgb.put("maroon", new int[] {128, 0, 0}); + htmlColorToRgb.put("navy", new int[] {0, 0, 128}); + htmlColorToRgb.put("olive", new int[] {128, 128, 0}); + htmlColorToRgb.put("orange", new int[] {255, 165, 0}); + htmlColorToRgb.put("pink", new int[] {255, 192, 203}); + htmlColorToRgb.put("purple", new int[] {128, 0, 128}); + htmlColorToRgb.put("violet", new int[] {128, 0, 128}); + htmlColorToRgb.put("red", new int[] {255, 0, 0}); + htmlColorToRgb.put("silver", new int[] {192, 192, 192}); + htmlColorToRgb.put("white", new int[] {255, 255, 255}); + htmlColorToRgb.put("yellow", new int[] {255, 255, 0}); } protected int[] endColor; @@ -203,7 +220,6 @@ public class Fx { color += color; } result[i] = Math.max(0, Math.min(255, Integer.parseInt(color, 16))); - } return result; @@ -231,7 +247,6 @@ public class Fx { } return result; } - } public String cssprop; @@ -256,15 +271,15 @@ public class Fx { public void applyValue(GQuery g, double progress) { double ret = (start + ((end - start) * progress)); - String value = ("px".equals(unit) ? ((int) ret) : ret) + unit; + String val = ("px".equals(unit) ? ((int) ret) : ret) + unit; if ("scrollTop".equals(cssprop)) { - g.scrollTop((int)ret); + g.scrollTop((int) ret); } else if ("scrollLeft".equals(cssprop)) { - g.scrollLeft((int)ret); + g.scrollLeft((int) ret); } else if (attribute != null) { - g.attr(attribute, value); + g.attr(attribute, val); } else { - g.css(cssprop, value); + g.css(cssprop, val); } } @@ -273,5 +288,4 @@ public class Fx { + " value=" + value + " start=" + start + " end=" + end + " unit=" + unit).replaceAll("\\.0([^\\d])", "$1"); } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/PropertiesAnimation.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/PropertiesAnimation.java index 0c9d109c..e5a4c8f6 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/PropertiesAnimation.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/PropertiesAnimation.java @@ -37,17 +37,18 @@ public class PropertiesAnimation extends GQAnimation { /** * Easing method to use. */ - public static interface Easing { - public double interpolate(double progress); + public interface Easing { + double interpolate(double progress); + /** * @deprecated use EasingCurve.linear instead */ - public Easing LINEAR = EasingCurve.linear; + Easing LINEAR = EasingCurve.linear; /** * @deprecated use EasingCurve.swing instead */ - public Easing SWING = EasingCurve.swing; + Easing SWING = EasingCurve.swing; } /** @@ -73,71 +74,89 @@ public class PropertiesAnimation extends GQAnimation { * */ public static enum EasingCurve implements Easing { - linear (0, 0, 1, 1) { - public double interpolate(double p){return p;} - public String toString() {return "linear";} - }, - ease (0.25, 0.1, 0.25, 1) { - public String toString() {return "ease";} - }, - easeIn (0.42, 0, 1, 1) { - public String toString() {return "ease-in";} - }, - easeOut (0, 0, 0.58, 1) { - public String toString() {return "ease-out";} - }, - easeInOut (0.42, 0, 0.58, 1) { - public String toString() {return "ease-in-out";} - }, - snap (0,1,.5,1), - swing (.02,.01,.47,1), - easeInCubic (.550,.055,.675,.190), - easeOutCubic (.215,.61,.355,1), - easeInOutCubic (.645,.045,.355,1), - easeInCirc (.6,.04,.98,.335), - easeOutCirc (.075,.82,.165,1), - easeInOutCirc (.785,.135,.15,.86), - easeInExpo (.95,.05,.795,.035), - easeOutExpo (.19,1,.22,1), - easeInOutExpo (1,0,0,1), - easeInQuad (.55,.085,.68,.53), - easeOutQuad (.25,.46,.45,.94), - easeInOutQuad (.455,.03,.515,.955), - easeInQuart (.895,.03,.685,.22), - easeOutQuart (.165,.84,.44,1), - easeInOutQuart (.77,0,.175,1), - easeInQuint (.755,.05,.855,.06), - easeOutQuint (.23,1,.32,1), - easeInOutQuint (.86,0,.07,1), - easeInSine (.47,0,.745,.715), - easeOutSine (.39,.575,.565,1), - easeInOutSine (.445,.05,.55,.95), - easeInBack (.6,-.28,.735,.045), - easeOutBack (.175, .885,.32,1.275), - easeInOutBack (.68,-.55,.265,1.55), - custom(0, 0, 1, 1); - - private Bezier c = new Bezier(0, 0, 1, 1); - EasingCurve(double x1, double y1, double x2, double y2) { - with(x1, y1, x2, y2); - } - public Easing with(double x1, double y1, double x2, double y2) { - c = new Bezier(x1, y1, x2, y2); - return this; - } - public double interpolate(double progress) { - return c.f(progress); - } - public String toString() { + linear(0, 0, 1, 1) { + public double interpolate(double p) { + return p; + } + + public String toString() { + return "linear"; + } + }, + ease(0.25, 0.1, 0.25, 1) { + public String toString() { + return "ease"; + } + }, + easeIn(0.42, 0, 1, 1) { + public String toString() { + return "ease-in"; + } + }, + easeOut(0, 0, 0.58, 1) { + public String toString() { + return "ease-out"; + } + }, + easeInOut(0.42, 0, 0.58, 1) { + public String toString() { + return "ease-in-out"; + } + }, + snap(0, 1, .5, 1), + swing(.02, .01, .47, 1), + easeInCubic(.550, .055, .675, .190), + easeOutCubic(.215, .61, .355, 1), + easeInOutCubic(.645, .045, .355, 1), + easeInCirc(.6, .04, .98, .335), + easeOutCirc(.075, .82, .165, 1), + easeInOutCirc(.785, .135, .15, .86), + easeInExpo(.95, .05, .795, .035), + easeOutExpo(.19, 1, .22, 1), + easeInOutExpo(1, 0, 0, 1), + easeInQuad(.55, .085, .68, .53), + easeOutQuad(.25, .46, .45, .94), + easeInOutQuad(.455, .03, .515, .955), + easeInQuart(.895, .03, .685, .22), + easeOutQuart(.165, .84, .44, 1), + easeInOutQuart(.77, 0, .175, 1), + easeInQuint(.755, .05, .855, .06), + easeOutQuint(.23, 1, .32, 1), + easeInOutQuint(.86, 0, .07, 1), + easeInSine(.47, 0, .745, .715), + easeOutSine(.39, .575, .565, 1), + easeInOutSine(.445, .05, .55, .95), + easeInBack(.6, -.28, .735, .045), + easeOutBack(.175, .885, .32, 1.275), + easeInOutBack(.68, -.55, .265, 1.55), + custom(0, 0, 1, 1); + + private Bezier c = new Bezier(0, 0, 1, 1); + + EasingCurve(double x1, double y1, double x2, double y2) { + with(x1, y1, x2, y2); + } + + public Easing with(double x1, double y1, double x2, double y2) { + c = new Bezier(x1, y1, x2, y2); + return this; + } + + public double interpolate(double progress) { + return c.f(progress); + } + + public String toString() { return "cubic-bezier(" + c + ")"; - } - } + } + } - protected static final String[] ATTRS_TO_SAVE = new String[]{"overflow"}; + protected static final String[] ATTRS_TO_SAVE = new String[] {"overflow"}; private static final RegExp REGEX_NUMBER_UNIT = RegExp.compile("^([0-9+-.]+)(.*)?$"); - protected static final RegExp REGEX_SYMBOL_NUMBER_UNIT = RegExp.compile("^([+-]=)?([0-9+-.]+)(.*)?$"); + protected static final RegExp REGEX_SYMBOL_NUMBER_UNIT = RegExp + .compile("^([+-]=)?([0-9+-.]+)(.*)?$"); protected static final RegExp REGEX_NON_PIXEL_ATTRS = RegExp.compile("z-?index|font-?weight|opacity|zoom|line-?height|scale|rotation|^\\$", "i"); @@ -146,7 +165,7 @@ public class PropertiesAnimation extends GQAnimation { private static final RegExp REGEX_BORDERCOLOR = RegExp.compile("^bordercolor$", "i"); - private static final RegExp REGEX_BACKGROUNDCOLOR =RegExp.compile("^backgroundcolor$", "i"); + private static final RegExp REGEX_BACKGROUNDCOLOR = RegExp.compile("^backgroundcolor$", "i"); public static Fx computeFxProp(Element e, String key, String val, boolean hidden) { @@ -170,7 +189,8 @@ public class PropertiesAnimation extends GQAnimation { // transparent) Element current = e; - while ((initialColor == null || initialColor.length() == 0 || initialColor.equals("transparent")) + while ((initialColor == null || initialColor.length() == 0 || initialColor + .equals("transparent")) && current != null) { initialColor = GQuery.$(current).css(key, false); current = !"body".equalsIgnoreCase(current.getTagName()) @@ -212,10 +232,10 @@ public class PropertiesAnimation extends GQAnimation { String attr = g.attr(rkey); MatchResult parts = REGEX_NUMBER_UNIT.exec(attr); if (parts != null) { - String $1 = parts.getGroup(1); - String $2 = parts.getGroup(2); - cur = Double.parseDouble($1); - unit = $2 == null ? "" : $2; + String p1 = parts.getGroup(1); + String p2 = parts.getGroup(2); + cur = Double.parseDouble(p1); + unit = p2 == null ? "" : p2; } else { cur = g.cur(key, true); key = rkey; @@ -241,26 +261,26 @@ public class PropertiesAnimation extends GQAnimation { MatchResult parts = REGEX_SYMBOL_NUMBER_UNIT.exec(val); if (parts != null) { - String $1 = parts.getGroup(1); - String $2 = parts.getGroup(2); - String $3 = parts.getGroup(3); - end = Double.parseDouble($2); + String p1 = parts.getGroup(1); + String p2 = parts.getGroup(2); + String p3 = parts.getGroup(3); + end = Double.parseDouble(p2); if (rkey == null) { unit = REGEX_NON_PIXEL_ATTRS.test(key) ? "" : // - $3 == null || $3.isEmpty() ? "px" : $3; + p3 == null || p3.isEmpty() ? "px" : p3; if (!"px".equals(unit)) { double to = end == 0 ? 1 : end; g.css(key, to + unit); start = to * start / g.cur(key, true); g.css(key, start + unit); } - } else if ($3 != null && !$3.isEmpty()) { - unit = $3; + } else if (p3 != null && !p3.isEmpty()) { + unit = p3; } - if ($1 != null && !$1.isEmpty()) { - end = (("-=".equals($1) ? -1 : 1) * end) + start; + if (p1 != null && !p1.isEmpty()) { + end = (("-=".equals(p1) ? -1 : 1) * end) + start; } } } @@ -298,7 +318,7 @@ public class PropertiesAnimation extends GQAnimation { @Override public void onCancel() { Boolean jumpToEnd = Effects.$(e).data(Effects.JUMP_TO_END, Boolean.class); - if (jumpToEnd != null && jumpToEnd){ + if (jumpToEnd != null && jumpToEnd) { onComplete(); } else { g.dequeue(); @@ -365,5 +385,4 @@ public class PropertiesAnimation extends GQAnimation { protected double interpolate(double progress) { return easing.interpolate(progress); } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/Transitions.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/Transitions.java index ac9581cd..fed2ffdf 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/Transitions.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/Transitions.java @@ -1,4 +1,19 @@ /* + * Copyright 2014, The gwtquery team. + * + * 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. + */ +/* * * Copyright 2013, The gwtquery team. * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except @@ -13,12 +28,6 @@ */ package com.google.gwt.query.client.plugins.effects; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map.Entry; - import com.google.gwt.core.client.Duration; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Style; @@ -34,10 +43,16 @@ import com.google.gwt.regexp.shared.RegExp; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Timer; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; + /** * Transitions and transformation plugin for gQuery. * - * It is inspired on jquery.transit (http://github.com/rstacruz/jquery.transit) + * It is inspired on jquery.transit (http://github.com/rstacruz/jquery.transit). * * Usage examples: * <pre> diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/TransitionsAnimation.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/TransitionsAnimation.java index a671d92e..6155540a 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/TransitionsAnimation.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/TransitionsAnimation.java @@ -30,10 +30,13 @@ import com.google.gwt.regexp.shared.MatchResult; /** * Animation effects on any numeric CSS3 property or transformation - * using CSS3 transitions + * using CSS3 transitions. */ public class TransitionsAnimation extends PropertiesAnimation { + /** + * TransitionAnimation with Clip capabilities. + */ public static class TransitionsClipAnimation extends TransitionsAnimation { private Action action; @@ -183,7 +186,6 @@ public class TransitionsAnimation extends PropertiesAnimation { trsStart = "" + start; g.css(key, start + unit); } - } else { trsStart = ""; trsEnd = val; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java index 5f3cf531..bfb24d2c 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java @@ -13,6 +13,8 @@ */ package com.google.gwt.query.client.plugins.events; +import static com.google.gwt.query.client.GQuery.$; + import com.google.gwt.core.client.Duration; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.EventTarget; @@ -31,13 +33,11 @@ import com.google.gwt.user.client.EventListener; import java.util.ArrayList; import java.util.List; -import static com.google.gwt.query.client.GQuery.$; - /** * This class implements an event queue instance for one Element. The queue instance is configured * as the default event listener in GWT. * - * The reference to this queue is stored as a unique variable in the element's DOM + * The reference to this queue is stored as a unique variable in the element's DOM. * * The class takes care of calling the appropriate functions for each browser event and it also * calls sinkEvents method. @@ -324,7 +324,6 @@ public class EventsListener implements EventListener { if (newFunctions.length() > 0) { bindFunctionBySelector.put(cssSelector, newFunctions); } - } } @@ -370,7 +369,6 @@ public class EventsListener implements EventListener { return Element.as(eventTarget); } - } public static final String EVENT_DATA = "___event_datas"; @@ -401,7 +399,7 @@ public class EventsListener implements EventListener { /** * We have to set the gQuery event listener to the element again when - * the element is a widget, because when GWT detaches a widget it removes the + * the element is a widget, because when GWT detaches a widget it removes the * event listener. */ public static void rebind(Element e) { @@ -412,44 +410,44 @@ public class EventsListener implements EventListener { } private static native void cleanGQListeners(Element elem) /*-{ - if (elem.__gwtlistener) { + if (elem.__gwtlistener) { @com.google.gwt.user.client.DOM::setEventListener(*)(elem, elem.__gwtlistener); - } - elem.__gwtlistener = elem.__gqueryevent = elem.__gquery = null; + } + elem.__gwtlistener = elem.__gqueryevent = elem.__gquery = null; }-*/; private static native EventsListener getGQueryEventListener(Element elem) /*-{ - return elem.__gqueryevent; + return elem.__gqueryevent; }-*/; private static native EventListener getGwtEventListener(Element elem) /*-{ - return elem.__gwtlistener; + return elem.__gwtlistener; }-*/; - private static native void init(Element elem, EventsListener gqevent)/*-{ - elem.__gwtlistener = @com.google.gwt.user.client.DOM::getEventListener(*)(elem); + private static native void init(Element elem, EventsListener gqevent) /*-{ + elem.__gwtlistener = @com.google.gwt.user.client.DOM::getEventListener(*)(elem); elem.__gqueryevent = gqevent; // Someone has reported that in IE the init can be called multiple times // causing a loop. We need some test to demonstrate this behaviour though. // Anyway we check this condition to avoid looping - if (elem.__gwtlistener == gqevent) elem.__gwtlistener = null; + if (elem.__gwtlistener == gqevent) elem.__gwtlistener = null; }-*/; private static native void sinkBitlessEvent(Element elem, String name) /*-{ - if (!elem.__gquery) - elem.__gquery = []; - if (elem.__gquery[name]) - return; - elem.__gquery[name] = true; - - var handle = function(event) { - elem.__gqueryevent.@com.google.gwt.query.client.plugins.events.EventsListener::onBrowserEvent(Lcom/google/gwt/user/client/Event;)(event); - }; - - if (elem.addEventListener) - elem.addEventListener(name, handle, true); - else - elem.attachEvent("on" + name, handle); + if (!elem.__gquery) + elem.__gquery = []; + if (elem.__gquery[name]) + return; + elem.__gquery[name] = true; + + var handle = function(event) { + elem.__gqueryevent.@com.google.gwt.query.client.plugins.events.EventsListener::onBrowserEvent(Lcom/google/gwt/user/client/Event;)(event); + }; + + if (elem.addEventListener) + elem.addEventListener(name, handle, true); + else + elem.attachEvent("on" + name, handle); }-*/; int eventBits = 0; @@ -493,8 +491,8 @@ public class EventsListener implements EventListener { String nameSpace = null; String eventName = event; - //seperate possible namespace - //jDramaix: I removed old regex ^([^.]*)\.?(.*$) because it didn't work on IE8... + // seperate possible namespace + // jDramaix: I removed old regex ^([^.]*)\.?(.*$) because it didn't work on IE8... String[] subparts = event.split("\\.", 2); if (subparts.length == 2){ @@ -502,7 +500,7 @@ public class EventsListener implements EventListener { eventName = subparts[0]; } - //handle special event like mouseenter or mouseleave + // handle special event like mouseenter or mouseleave SpecialEvent hook = special.get(eventName); eventName = hook != null ? hook.getDelegateType() : eventName; String originalEventName = hook != null ? hook.getOriginalType() : null; @@ -535,8 +533,8 @@ public class EventsListener implements EventListener { String nameSpace = null; String eventName = event; - //seperate possible namespace - //jDramaix: I removed old regex ^([^.]*)\.?(.*$) because it didn't work on IE8... + // seperate possible namespace + // jDramaix: I removed old regex ^([^.]*)\.?(.*$) because it didn't work on IE8... String[] subparts = event.split("\\.", 2); if (subparts.length == 2) { @@ -544,7 +542,7 @@ public class EventsListener implements EventListener { eventName = subparts[0]; } - //handle special event like mouseenter or mouseleave + // handle special event like mouseenter or mouseleave SpecialEvent hook = special.get(eventName); eventName = hook != null ? hook.getDelegateType() : eventName; String originalEventName = hook != null ? hook.getOriginalType() : null; @@ -553,8 +551,6 @@ public class EventsListener implements EventListener { die(b, nameSpace, eventName, originalEventName, cssSelector); } - - } public void die(int eventbits, String nameSpace, String eventName, String originalEventName, @@ -638,7 +634,6 @@ public class EventsListener implements EventListener { String nameSpace = null; String eventName = event; - String[] subparts = event.split("\\.", 2); if (subparts.length == 2) { @@ -646,7 +641,7 @@ public class EventsListener implements EventListener { eventName = subparts[0]; } - //handle special event like mouseenter or mouseleave + // handle special event like mouseenter or mouseleave SpecialEvent hook = special.get(eventName); eventName = hook != null ? hook.getDelegateType() : eventName; String originalEventName = hook != null ? hook.getOriginalType() : null; @@ -732,7 +727,7 @@ public class EventsListener implements EventListener { public void unbind(int eventbits, String namespace, String eventName, String originalEventType, Function f) { - + JsObjectArray<BindFunction> newList = JsObjectArray.createArray().cast(); for (int i = 0; i < elementEvents.length(); i++) { BindFunction listener = elementEvents.get(i); @@ -757,7 +752,6 @@ public class EventsListener implements EventListener { newList.add(listener); } elementEvents = newList; - } private boolean isNullOrEmpty(String s) { @@ -772,8 +766,8 @@ public class EventsListener implements EventListener { String nameSpace = null; String eventName = event; - //seperate possible namespace - //jDramaix: I removed old regex ^([^.]*)\.?(.*$) because it didn't work on IE8... + // seperate possible namespace + // jDramaix: I removed old regex ^([^.]*)\.?(.*$) because it didn't work on IE8... String[] subparts = event.split("\\.", 2); if (subparts.length == 2){ @@ -781,7 +775,7 @@ public class EventsListener implements EventListener { eventName = subparts[0]; } - //handle special event + // handle special event SpecialEvent hook = special.get(eventName); eventName = hook != null ? hook.getDelegateType() : eventName; String originalEventName = hook != null ? hook.getOriginalType() : null; @@ -813,7 +807,6 @@ public class EventsListener implements EventListener { } DOM.sinkEvents((com.google.gwt.user.client.Element) element, eventBits | DOM.getEventsSunk((com.google.gwt.user.client.Element) element)); - } else { sinkBitlessEvent(element, eventName); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/GqEvent.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/GqEvent.java index 1a92374f..a93e5491 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/GqEvent.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/GqEvent.java @@ -1,3 +1,18 @@ +/* + * Copyright 2014, The gwtquery team. + * + * 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.gwt.query.client.plugins.events; import com.google.gwt.dom.client.Element; @@ -14,20 +29,17 @@ import com.google.gwt.user.client.Event; * element. So, we cannot keep a copy of the MouseDownEvent during a dragging * for example. * - * - * * Be Careful : the methods preventDefault() and stopPropagation must be called directly on the * original event. * - * */ public class GqEvent extends Event { - public static native void setOriginalEventType(NativeEvent evt, String originalEventName)/*-{ + public static native void setOriginalEventType(NativeEvent evt, String originalEventName) /*-{ evt["__gwtquery_originalEventName"] = originalEventName; }-*/; - public static native String getOriginalEventType(Event evt)/*-{ + public static native String getOriginalEventType(Event evt) /*-{ return evt["__gwtquery_originalEventName"] || null; }-*/; @@ -47,34 +59,33 @@ public class GqEvent extends Event { private static native void copy( Event originalEvent, GqEvent gQueryEvent) /*-{ - for ( var field in originalEvent) { - gQueryEvent[field] = originalEvent[field]; - } - gQueryEvent.originalEvent = originalEvent; + for ( var field in originalEvent) { + gQueryEvent[field] = originalEvent[field]; + } + gQueryEvent.originalEvent = originalEvent; }-*/; - protected GqEvent() { } /** - * Return the original event (the one created by the browser) + * Return the original event (the one created by the browser). */ - public final native Event getOriginalEvent()/*-{ - return this.originalEvent; + public final native Event getOriginalEvent() /*-{ + return this.originalEvent; }-*/; - public final native void setCurrentElementTarget(Element e)/*-{ + public final native void setCurrentElementTarget(Element e) /*-{ this.currentTarget = e; - //ie don't have a currentEventTarget field on event + // ie don't have a currentEventTarget field on event try{ @com.google.gwt.dom.client.DOMImplTrident::currentEventTarget = e; }catch(e){} }-*/; /** - * Tell whether ctrl or cmd key is pressed + * Tell whether ctrl or cmd key is pressed. * */ public final boolean isMetaKeyPressed() { @@ -82,7 +93,7 @@ public class GqEvent extends Event { } /** - * The mouse position relative to the left edge of the document + * The mouse position relative to the left edge of the document. * */ public final int pageX() { @@ -104,5 +115,4 @@ public class GqEvent extends Event { return getClientY() + GQuery.document.getScrollTop(); } } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/ButtonWidgetFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/ButtonWidgetFactory.java index 39028149..fe99fb7b 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/ButtonWidgetFactory.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/ButtonWidgetFactory.java @@ -15,11 +15,8 @@ */ package com.google.gwt.query.client.plugins.widgets; - import com.google.gwt.dom.client.ButtonElement; import com.google.gwt.dom.client.Element; -import com.google.gwt.query.client.plugins.widgets.WidgetFactory; -import com.google.gwt.query.client.plugins.widgets.WidgetsUtils; import com.google.gwt.user.client.ui.Button; /** @@ -33,18 +30,18 @@ public class ButtonWidgetFactory implements WidgetFactory<Button> { Button button = new Button(); button.getElement().setInnerText(e.getInnerText()); - if ("button".equalsIgnoreCase(e.getTagName())){ - copyAttributes((ButtonElement)e.cast(), (ButtonElement)button.getElement().cast()); + if ("button".equalsIgnoreCase(e.getTagName())) { + copyAttributes((ButtonElement) e.cast(), (ButtonElement) button.getElement().cast()); } WidgetsUtils.replaceOrAppend(e, button); return button; } - protected void copyAttributes(ButtonElement source,ButtonElement destination) { + protected void copyAttributes(ButtonElement source, ButtonElement destination) { destination.setAccessKey(source.getAccessKey()); destination.setDisabled(source.isDisabled()); destination.setName(source.getName()); destination.setValue(source.getValue()); } -}
\ No newline at end of file +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/HtmlPanelWidgetFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/HtmlPanelWidgetFactory.java index e5c18f0a..c9c54dd6 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/HtmlPanelWidgetFactory.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/HtmlPanelWidgetFactory.java @@ -18,10 +18,12 @@ package com.google.gwt.query.client.plugins.widgets; import com.google.gwt.dom.client.Element; import com.google.gwt.user.client.ui.HTMLPanel; +/** + * HtmlPanelWidgetFactory. + */ public class HtmlPanelWidgetFactory implements WidgetFactory<HTMLPanel> { public HTMLPanel create(Element e) { return new WidgetsHtmlPanel(e); } - -}
\ No newline at end of file +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/LabelWidgetFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/LabelWidgetFactory.java index 0beb81d6..a6e01fff 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/LabelWidgetFactory.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/LabelWidgetFactory.java @@ -18,6 +18,9 @@ package com.google.gwt.query.client.plugins.widgets; import com.google.gwt.dom.client.Element; import com.google.gwt.user.client.ui.Label; +/** + * LabelWidgetFactory. + */ public class LabelWidgetFactory implements WidgetFactory<Label> { public Label create(Element e) { @@ -26,5 +29,4 @@ public class LabelWidgetFactory implements WidgetFactory<Label> { WidgetsUtils.replaceOrAppend(e, label); return label; } - -}
\ No newline at end of file +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TextAreaWidgetFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TextAreaWidgetFactory.java index eff780f5..fe5a9e5e 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TextAreaWidgetFactory.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TextAreaWidgetFactory.java @@ -27,7 +27,7 @@ public class TextAreaWidgetFactory extends TextBoxBaseWidgetFactory<TextArea> { @Override protected void copyAttributes(Element src, Element dest) { - TextAreaElement source= src.cast(); + TextAreaElement source = src.cast(); TextAreaElement destination = dest.cast(); destination.setAccessKey(source.getAccessKey()); @@ -45,8 +45,7 @@ public class TextAreaWidgetFactory extends TextBoxBaseWidgetFactory<TextArea> { return "textarea"; } - protected TextArea createWidget() { return new TextArea(); } -}
\ No newline at end of file +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TextBoxBaseWidgetFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TextBoxBaseWidgetFactory.java index 9a7f22eb..4ca5179b 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TextBoxBaseWidgetFactory.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TextBoxBaseWidgetFactory.java @@ -20,8 +20,9 @@ import com.google.gwt.dom.client.InputElement; import com.google.gwt.user.client.ui.TextBoxBase; /** + * TextBoxBaseWidgetFactory. * - * + * @param <T> */ public abstract class TextBoxBaseWidgetFactory<T extends TextBoxBase> implements WidgetFactory<T> { @@ -40,7 +41,7 @@ public abstract class TextBoxBaseWidgetFactory<T extends TextBoxBase> return (T) textBox; } - protected String getEquivalentTagName(){ + protected String getEquivalentTagName() { return "input"; } @@ -51,7 +52,8 @@ public abstract class TextBoxBaseWidgetFactory<T extends TextBoxBase> destination.setAccessKey(source.getAccessKey()); destination.setDefaultValue(source.getDefaultValue()); destination.setDisabled(source.isDisabled()); - if (source.getMaxLength() > 0) destination.setMaxLength(source.getMaxLength()); + if (source.getMaxLength() > 0) + destination.setMaxLength(source.getMaxLength()); destination.setReadOnly(source.isReadOnly()); destination.setSize(source.getSize()); destination.setName(source.getName()); @@ -59,4 +61,4 @@ public abstract class TextBoxBaseWidgetFactory<T extends TextBoxBase> } protected abstract T createWidget(); -}
\ No newline at end of file +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TextBoxWidgetFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TextBoxWidgetFactory.java index cf650fb3..3d9c317d 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TextBoxWidgetFactory.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TextBoxWidgetFactory.java @@ -28,4 +28,4 @@ public class TextBoxWidgetFactory extends TextBoxBaseWidgetFactory<TextBox> { protected TextBox createWidget() { return new TextBox(); } -}
\ No newline at end of file +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetFactory.java index abd94ef1..82ab0c54 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetFactory.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetFactory.java @@ -19,11 +19,10 @@ import com.google.gwt.dom.client.Element; import com.google.gwt.user.client.ui.Widget; /** - * Factory interface - * - * @param <W> - * @param <O> - */ - public interface WidgetFactory<W extends Widget> { - public W create(Element e); - }
\ No newline at end of file + * Factory interface. + * + * @param <W> + */ +public interface WidgetFactory<W extends Widget> { + W create(Element e); +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetInitializer.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetInitializer.java index 47369c82..806edfcb 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetInitializer.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetInitializer.java @@ -18,11 +18,16 @@ package com.google.gwt.query.client.plugins.widgets; import com.google.gwt.dom.client.Element; import com.google.gwt.user.client.ui.Widget; +/** + * WidgetInitializer. + * + * @param <W> + */ public interface WidgetInitializer<W extends Widget> { - /** - * Initialize the newly created widget <code>w</code>. The element <code>e</code> - * is the element used to construct the widget. - * - */ - void initialize(W w, Element e); - } + /** + * Initialize the newly created widget <code>w</code>. The element <code>e</code> + * is the element used to construct the widget. + * + */ + void initialize(W w, Element e); +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetsHtmlPanel.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetsHtmlPanel.java index 657f1ff6..d216df1e 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetsHtmlPanel.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetsHtmlPanel.java @@ -60,9 +60,9 @@ public class WidgetsHtmlPanel extends HTMLPanel { } /** - * use jsni to access private attribute + * use jsni to access private attribute. */ - private native void setElementImpl(Element e)/*-{ + private native void setElementImpl(Element e) /*-{ this.@com.google.gwt.user.client.ui.UIObject::element = e; }-*/; @@ -110,7 +110,6 @@ public class WidgetsHtmlPanel extends HTMLPanel { if (RootPanel.isInDetachList(w)) { RootPanel.detachNow(w); } - } else if (parent instanceof HTMLPanel) { WidgetsUtils.doLogicalDetachFromHtmlPanel(w); } else { @@ -126,6 +125,5 @@ public class WidgetsHtmlPanel extends HTMLPanel { } adopt(w); - } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetsUtils.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetsUtils.java index 408d1336..c48082c7 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetsUtils.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetsUtils.java @@ -17,8 +17,6 @@ package com.google.gwt.query.client.plugins.widgets; import static com.google.gwt.query.client.GQuery.$; -import java.util.Iterator; - import com.google.gwt.dom.client.BodyElement; import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Element; @@ -35,29 +33,33 @@ import com.google.gwt.user.client.ui.SimplePanel; import com.google.gwt.user.client.ui.Widget; import com.google.gwt.user.client.ui.WidgetCollection; +import java.util.Iterator; + +/** + * WidgetsUtils. + */ public class WidgetsUtils { static final String[] appendingTags = { - "td", "th", "li"}; - + "td", "th", "li"}; /** * Append a widget to a dom element, and hide it. * Element classes will be copied to the new widget. */ - public static void hideAndAfter(Element e, Widget widget) { - assert e != null && widget != null; - if ($(e).widget() != null && $(e).widget().isAttached()) { - replaceWidget($(e).widget(), widget, false); - } else { - detachWidget(widget); - hideAndAfter(e, widget.getElement()); - attachWidget(widget, getFirstParentWidget(widget)); - } - } + public static void hideAndAfter(Element e, Widget widget) { + assert e != null && widget != null; + if ($(e).widget() != null && $(e).widget().isAttached()) { + replaceWidget($(e).widget(), widget, false); + } else { + detachWidget(widget); + hideAndAfter(e, widget.getElement()); + attachWidget(widget, getFirstParentWidget(widget)); + } + } /** - * Test if the tag name of the element is one of tag names given in parameter + * Test if the tag name of the element is one of tag names given in parameter. * * @param tagNames * @return @@ -77,205 +79,202 @@ public class WidgetsUtils { regExp.append(")$"); return e.getTagName().toUpperCase().matches(regExp.toString()); - } - /** - * Replace a dom element by a widget. - * Old element classes will be copied to the new widget. - */ - public static void replaceOrAppend(Element e, Widget widget) { - assert e != null && widget != null; - if ($(e).widget() != null && $(e).widget().isAttached()) { - replaceWidget($(e).widget(), widget, true); - } else { - detachWidget(widget); - replaceOrAppend(e, widget.getElement()); - attachWidget(widget, getFirstParentWidget(widget)); - } - } + /** + * Replace a dom element by a widget. + * Old element classes will be copied to the new widget. + */ + public static void replaceOrAppend(Element e, Widget widget) { + assert e != null && widget != null; + if ($(e).widget() != null && $(e).widget().isAttached()) { + replaceWidget($(e).widget(), widget, true); + } else { + detachWidget(widget); + replaceOrAppend(e, widget.getElement()); + attachWidget(widget, getFirstParentWidget(widget)); + } + } - private static Widget getFirstParentWidget(Widget w) { - Element e = w.getElement().getParentElement(); - BodyElement body = Document.get().getBody(); - while ((e != null) && (body != e)) { - if (Event.getEventListener(e) != null) { - Widget p = $(e).widget(); - if (p != null){ - return p; - } - } - e = e.getParentElement(); - } - return null; - } + private static Widget getFirstParentWidget(Widget w) { + Element e = w.getElement().getParentElement(); + BodyElement body = Document.get().getBody(); + while ((e != null) && (body != e)) { + if (Event.getEventListener(e) != null) { + Widget p = $(e).widget(); + if (p != null) { + return p; + } + } + e = e.getParentElement(); + } + return null; + } - private static void hideAndAfter(Element oldElement, Element newElement) { - assert oldElement != null && newElement != null; - GQuery.$(oldElement).hide().after(newElement); - String c = oldElement.getClassName(); - if (!c.isEmpty()) { - newElement.addClassName(c); - } - } + private static void hideAndAfter(Element oldElement, Element newElement) { + assert oldElement != null && newElement != null; + GQuery.$(oldElement).hide().after(newElement); + String c = oldElement.getClassName(); + if (!c.isEmpty()) { + newElement.addClassName(c); + } + } - /** + /** * If the <code>oldElement</code> is a td, th, li tags, the new element will replaced its content. * In other cases, the <code>oldElement</code> will be replaced by the <code>newElement</code> * and the old element classes will be copied to the new element. */ - private static void replaceOrAppend(Element oldElement, Element newElement) { + private static void replaceOrAppend(Element oldElement, Element newElement) { assert oldElement != null && newElement != null; - if(matchesTags(oldElement, appendingTags)){ + if (matchesTags(oldElement, appendingTags)) { GQuery.$(oldElement).html("").append(newElement); - }else{ + } else { GQuery.$(oldElement).replaceWith(newElement); - //copy class + // copy class String c = oldElement.getClassName(); if (!c.isEmpty()) { newElement.addClassName(c); } - //copy id + // copy id newElement.setId(oldElement.getId()); - //ensure no duplicate id + // ensure no duplicate id oldElement.setId(""); - } - } + } - private static void replaceWidget(Widget oldWidget, Widget newWidget, boolean remove) { - Widget parent = oldWidget.getParent(); - boolean removed = false; - // TODO: handle tables - if (parent instanceof HTMLPanel) { - ((HTMLPanel) parent).addAndReplaceElement(newWidget, - (com.google.gwt.dom.client.Element)oldWidget.getElement()); - if (!remove) { - $(newWidget).before($(oldWidget)); - } - removed = true; - } else if (parent instanceof ComplexPanel) { - ((ComplexPanel) parent).add(newWidget); - } else if (parent instanceof SimplePanel) { - ((SimplePanel) parent).setWidget(newWidget); - } else if (parent instanceof Panel) { - ((Panel) parent).add(newWidget); - } else { - assert false : "Can not replace an attached widget whose parent is a " + parent.getClass().getName(); - } - if (remove && !removed && oldWidget.isAttached()) { - oldWidget.removeFromParent(); - } else { - oldWidget.setVisible(false); - } - } + private static void replaceWidget(Widget oldWidget, Widget newWidget, boolean remove) { + Widget parent = oldWidget.getParent(); + boolean removed = false; + // TODO: handle tables + if (parent instanceof HTMLPanel) { + ((HTMLPanel) parent).addAndReplaceElement(newWidget, + (com.google.gwt.dom.client.Element) oldWidget.getElement()); + if (!remove) { + $(newWidget).before($(oldWidget)); + } + removed = true; + } else if (parent instanceof ComplexPanel) { + ((ComplexPanel) parent).add(newWidget); + } else if (parent instanceof SimplePanel) { + ((SimplePanel) parent).setWidget(newWidget); + } else if (parent instanceof Panel) { + ((Panel) parent).add(newWidget); + } else { + assert false : "Can not replace an attached widget whose parent is a " + + parent.getClass().getName(); + } + if (remove && !removed && oldWidget.isAttached()) { + oldWidget.removeFromParent(); + } else { + oldWidget.setVisible(false); + } + } - /** - * Attach a widget to the GWT widget list. Normally used when GQuery - * creates widgets wrapping existing dom elements. - * It does nothing if the widget is already attached to another widget. - * - * @param widget to attach - * @param firstParentWidget the parent widget, - * If it is null and it is not inside any other widget, we just add - * the widget to the gwt detach list - */ - public static void attachWidget(Widget widget, Widget firstParentWidget) { - if (widget != null && widget.getParent() == null) { - if (firstParentWidget == null) { - firstParentWidget = getFirstParentWidget(widget); - if (firstParentWidget == null) { - RootPanel.detachOnWindowClose(widget); - widgetOnAttach(widget); - } else { - attachWidget(widget, firstParentWidget); - } - } else if (firstParentWidget instanceof HTMLPanel) { - HTMLPanel h = (HTMLPanel) firstParentWidget; - Element p = widget.getElement().getParentElement(); - if (p != null) { - h.add(widget, p); - } else { - h.add(widget); - } - } else if (firstParentWidget instanceof HasOneWidget) { - ((HasOneWidget)firstParentWidget).setWidget(widget); - } else if (firstParentWidget instanceof HasWidgets) { - try { - ((HasWidgets)firstParentWidget).add(widget); - } catch (UnsupportedOperationException e) { - // Some widgets like 'table' has no implementation of 'add(widget)' - widgetSetParent(widget, firstParentWidget); - } - } else { - widgetSetParent(widget, firstParentWidget); - } - } - } + /** + * Attach a widget to the GWT widget list. Normally used when GQuery + * creates widgets wrapping existing dom elements. + * It does nothing if the widget is already attached to another widget. + * + * @param widget to attach + * @param firstParentWidget the parent widget, + * If it is null and it is not inside any other widget, we just add + * the widget to the gwt detach list + */ + public static void attachWidget(Widget widget, Widget firstParentWidget) { + if (widget != null && widget.getParent() == null) { + if (firstParentWidget == null) { + firstParentWidget = getFirstParentWidget(widget); + if (firstParentWidget == null) { + RootPanel.detachOnWindowClose(widget); + widgetOnAttach(widget); + } else { + attachWidget(widget, firstParentWidget); + } + } else if (firstParentWidget instanceof HTMLPanel) { + HTMLPanel h = (HTMLPanel) firstParentWidget; + Element p = widget.getElement().getParentElement(); + if (p != null) { + h.add(widget, p); + } else { + h.add(widget); + } + } else if (firstParentWidget instanceof HasOneWidget) { + ((HasOneWidget) firstParentWidget).setWidget(widget); + } else if (firstParentWidget instanceof HasWidgets) { + try { + ((HasWidgets) firstParentWidget).add(widget); + } catch (UnsupportedOperationException e) { + // Some widgets like 'table' has no implementation of 'add(widget)' + widgetSetParent(widget, firstParentWidget); + } + } else { + widgetSetParent(widget, firstParentWidget); + } + } + } - /** - * Remove a widget from the detach list - */ - public static void detachWidget(final Widget widget) { - if (widget != null) { - widget.removeFromParent(); - } - } + /** + * Remove a widget from the detach list. + */ + public static void detachWidget(final Widget widget) { + if (widget != null) { + widget.removeFromParent(); + } + } - /** - * This method detach a widget of its parent without doing a physical - * detach (DOM manipulation) - * - * @param w - */ - public static void doLogicalDetachFromHtmlPanel(Widget w) { - Widget parent = w.getParent(); + /** + * This method detach a widget of its parent without doing a physical + * detach (DOM manipulation). + */ + public static void doLogicalDetachFromHtmlPanel(Widget w) { + Widget parent = w.getParent(); - if (parent instanceof HTMLPanel) { - complexPanelGetChildren((HTMLPanel) parent).remove(w); - widgetSetParent(w, null); - } else{ - throw new IllegalStateException( - "You can only use this method to detach a child from an HTMLPanel"); - } - } + if (parent instanceof HTMLPanel) { + complexPanelGetChildren((HTMLPanel) parent).remove(w); + widgetSetParent(w, null); + } else { + throw new IllegalStateException( + "You can only use this method to detach a child from an HTMLPanel"); + } + } - /** - * Return children of the first widget's panel - */ - public static Iterator<Widget> getChildren(Widget w){ - if(w instanceof Panel){ - return ((Panel)w).iterator(); - } - if(w instanceof Composite){ - return getChildren(compositeGetWidget((Composite)w)); - } - return null; - } + /** + * Return children of the first widget's panel. + */ + public static Iterator<Widget> getChildren(Widget w) { + if (w instanceof Panel) { + return ((Panel) w).iterator(); + } + if (w instanceof Composite) { + return getChildren(compositeGetWidget((Composite) w)); + } + return null; + } - /** - * Return the first widget parent of the element, or null if it is not - * attached to any widget yet. - */ - private static Widget getFirstParentWidgetElement(Element element) { - return $(element).parents().widget(); - } + /** + * Return the first widget parent of the element, or null if it is not + * attached to any widget yet. + */ + private static Widget getFirstParentWidgetElement(Element element) { + return $(element).parents().widget(); + } - private static native void widgetOnAttach(Widget w) /*-{ - w.@com.google.gwt.user.client.ui.Widget::onAttach()(); - }-*/; + private static native void widgetOnAttach(Widget w) /*-{ + w.@com.google.gwt.user.client.ui.Widget::onAttach()(); + }-*/; - private static native void widgetSetParent(Widget w, Widget p) /*-{ - w.@com.google.gwt.user.client.ui.Widget::setParent(Lcom/google/gwt/user/client/ui/Widget;)(p); - }-*/; + private static native void widgetSetParent(Widget w, Widget p) /*-{ + w.@com.google.gwt.user.client.ui.Widget::setParent(Lcom/google/gwt/user/client/ui/Widget;)(p); + }-*/; - private static native Widget compositeGetWidget(Composite w) /*-{ - return w.@com.google.gwt.user.client.ui.Composite::getWidget()(); - }-*/; + private static native Widget compositeGetWidget(Composite w) /*-{ + return w.@com.google.gwt.user.client.ui.Composite::getWidget()(); + }-*/; - private static native WidgetCollection complexPanelGetChildren(ComplexPanel w) /*-{ - return w.@com.google.gwt.user.client.ui.ComplexPanel::getChildren()(); - }-*/; + private static native WidgetCollection complexPanelGetChildren(ComplexPanel w) /*-{ + return w.@com.google.gwt.user.client.ui.ComplexPanel::getChildren()(); + }-*/; } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/linker/IFrameWithDocTypeLinker.java b/gwtquery-core/src/main/java/com/google/gwt/query/linker/IFrameWithDocTypeLinker.java index bc5ff169..0f36edff 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/linker/IFrameWithDocTypeLinker.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/linker/IFrameWithDocTypeLinker.java @@ -36,8 +36,10 @@ public class IFrameWithDocTypeLinker extends IFrameLinker { @Deprecated protected String getModulePrefix(TreeLogger logger, LinkerContext context, String strongName) throws UnableToCompleteException { - logger.log(Type.WARN, - "GQuery IFrameWithDocTypeLinker is deprecated, remove <add-linker name=\"stddoctype\"/> from your module file"); + logger + .log( + Type.WARN, + "GQuery IFrameWithDocTypeLinker is deprecated, remove <add-linker name=\"stddoctype\"/> from your module file"); return DOCTYPE + super.getModulePrefix(logger, context, strongName); } @@ -45,11 +47,11 @@ public class IFrameWithDocTypeLinker extends IFrameLinker { @Deprecated protected String getModulePrefix(TreeLogger logger, LinkerContext context, String strongName, int numFragments) throws UnableToCompleteException { - logger.log(Type.WARN, - "GQuery IFrameWithDocTypeLinker is deprecated, remove <add-linker name=\"stddoctype\"/> from your module file"); + logger + .log( + Type.WARN, + "GQuery IFrameWithDocTypeLinker is deprecated, remove <add-linker name=\"stddoctype\"/> from your module file"); return DOCTYPE + super.getModulePrefix(logger, context, strongName, numFragments); - } } - diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/BrowserGenerator.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/BrowserGenerator.java index 3f18fd10..91dd539d 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/BrowserGenerator.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/BrowserGenerator.java @@ -15,8 +15,6 @@ */ package com.google.gwt.query.rebind; -import java.io.PrintWriter; - import com.google.gwt.core.ext.BadPropertyValueException; import com.google.gwt.core.ext.Generator; import com.google.gwt.core.ext.GeneratorContext; @@ -28,15 +26,18 @@ import com.google.gwt.core.ext.typeinfo.TypeOracle; import com.google.gwt.user.rebind.ClassSourceFileComposerFactory; import com.google.gwt.user.rebind.SourceWriter; +import java.io.PrintWriter; + /** - * Creates an implementation for {@link Browser} + * Creates an implementation for {@link Browser}. */ public class BrowserGenerator extends Generator { @Override - public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException { + public String generate(TreeLogger logger, GeneratorContext context, String typeName) + throws UnableToCompleteException { TypeOracle oracle = context.getTypeOracle(); PropertyOracle propOracle = context.getPropertyOracle(); - + String ua = null; try { ua = propOracle.getSelectionProperty(logger, "user.agent").getCurrentValue(); @@ -44,19 +45,19 @@ public class BrowserGenerator extends Generator { logger.log(TreeLogger.ERROR, "Can not resolve user.agent property", e); throw new UnableToCompleteException(); } - + JClassType clz = oracle.findType(typeName); String pName = clz.getPackage().getName(); String cName = clz.getName() + "_" + ua; - + PrintWriter pWriter = context.tryCreate(logger, pName, cName); - + if (pWriter != null) { ClassSourceFileComposerFactory cFact = new ClassSourceFileComposerFactory(pName, cName); cFact.setSuperclass(pName + "." + clz.getName()); - + SourceWriter writer = cFact.createSourceWriter(context, pWriter); - + writer.println("protected boolean isWebkit() {return " + "safari".equals(ua) + ";}"); writer.println("protected boolean isSafari() {return " + "safari".equals(ua) + ";}"); writer.println("protected boolean isOpera() {return " + "opera".equals(ua) + ";}"); @@ -68,17 +69,17 @@ public class BrowserGenerator extends Generator { writer.println("protected boolean isIe10() {return " + "ie10".equals(ua) + ";}"); writer.println("protected boolean isIe11() {return " + "gecko1_8".equals(ua) + ";}"); writer.println("public String toString() {return \"Browser:\"" + - " + \" webkit=\" + webkit" + + " + \" webkit=\" + webkit" + " + \" mozilla=\" + mozilla" + " + \" opera=\" + opera" + " + \" msie=\" + msie" + " + \" ie6=\" + ie6" + " + \" ie8=\" + ie8" + - " + \" ie9=\" + ie9" + + " + \" ie9=\" + ie9" + ";}"); writer.commit(logger); } - + return pName + "." + cName; } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/JsniBundleGenerator.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/JsniBundleGenerator.java index 4231fd2e..cfd9893e 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/JsniBundleGenerator.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/JsniBundleGenerator.java @@ -15,16 +15,6 @@ */ package com.google.gwt.query.rebind; -import java.io.IOException; -import java.io.InputStream; -import java.io.PrintWriter; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.zip.GZIPInputStream; -import java.util.zip.InflaterInputStream; - -import org.apache.commons.io.output.ByteArrayOutputStream; - import com.google.gwt.core.ext.Generator; import com.google.gwt.core.ext.GeneratorContext; import com.google.gwt.core.ext.TreeLogger; @@ -32,12 +22,21 @@ import com.google.gwt.core.ext.UnableToCompleteException; import com.google.gwt.core.ext.typeinfo.JClassType; import com.google.gwt.core.ext.typeinfo.JMethod; import com.google.gwt.core.ext.typeinfo.TypeOracle; -import com.google.gwt.query.client.builders.JsniBundle; import com.google.gwt.query.client.builders.JsniBundle.LibrarySource; import com.google.gwt.query.client.builders.JsniBundle.MethodSource; import com.google.gwt.user.rebind.ClassSourceFileComposerFactory; import com.google.gwt.user.rebind.SourceWriter; +import org.apache.commons.io.output.ByteArrayOutputStream; + +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintWriter; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.zip.GZIPInputStream; +import java.util.zip.InflaterInputStream; + /** * Generates an implementation of a user-defined interface <code>T</code> that * extends {@link JsniBundle}. @@ -61,7 +60,8 @@ public class JsniBundleGenerator extends Generator { PrintWriter pw = context.tryCreate(logger, packageName, className); if (pw != null) { - ClassSourceFileComposerFactory fact = new ClassSourceFileComposerFactory(packageName, className); + ClassSourceFileComposerFactory fact = + new ClassSourceFileComposerFactory(packageName, className); if (clazz.isInterface() != null) { fact.addImplementedInterface(requestedClass); } else { @@ -93,14 +93,14 @@ public class JsniBundleGenerator extends Generator { } try { // Read the javascript content - String content = getContent(logger, packageName.replace(".", "/") , value); + String content = getContent(logger, packageName.replace(".", "/"), value); // Adjust javascript so as we can introduce it in a JSNI comment block without // breaking java syntax. String jsni = parseJavascriptSource(content); for (int i = 0; i < replace.length - 1; i += 2) { - jsni = jsni.replaceAll(replace[i], replace[i+1]); + jsni = jsni.replaceAll(replace[i], replace[i + 1]); } pw.println(method.toString().replace("abstract", "native") + "/*-{"); @@ -109,7 +109,8 @@ public class JsniBundleGenerator extends Generator { pw.println(postpend); pw.println("}-*/;"); } catch (Exception e) { - logger.log(TreeLogger.ERROR, "Error parsing javascript source: " + value + " "+ e.getMessage()); + logger.log(TreeLogger.ERROR, "Error parsing javascript source: " + value + " " + + e.getMessage()); throw new UnableToCompleteException(); } } @@ -123,20 +124,23 @@ public class JsniBundleGenerator extends Generator { /** * Get the content of a javascript source. It supports remote sources hosted in CDN's. */ - private String getContent(TreeLogger logger, String path, String src) throws UnableToCompleteException { + private String getContent(TreeLogger logger, String path, String src) + throws UnableToCompleteException { HttpURLConnection connection = null; InputStream in = null; try { if (!src.matches("(?i)https?://.*")) { String file = path + "/" + src; - logger.log(TreeLogger.INFO, getClass().getSimpleName() + " - importing external javascript: " + file); + logger.log(TreeLogger.INFO, getClass().getSimpleName() + + " - importing external javascript: " + file); in = this.getClass().getClassLoader().getResourceAsStream(file); if (in == null) { logger.log(TreeLogger.ERROR, "Unable to read javascript file: " + file); } } else { - logger.log(TreeLogger.INFO, getClass().getSimpleName() + " - downloading external javascript: " + src); + logger.log(TreeLogger.INFO, getClass().getSimpleName() + + " - downloading external javascript: " + src); URL url = new URL(src); connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Accept-Encoding", "gzip, deflate"); @@ -146,7 +150,8 @@ public class JsniBundleGenerator extends Generator { int status = connection.getResponseCode(); if (status != HttpURLConnection.HTTP_OK) { - logger.log(TreeLogger.ERROR, "Server Error: " + status + " " + connection.getResponseMessage()); + logger.log(TreeLogger.ERROR, "Server Error: " + status + " " + + connection.getResponseMessage()); throw new UnableToCompleteException(); } @@ -191,8 +196,8 @@ public class JsniBundleGenerator extends Generator { boolean isSingQuot = false; boolean isDblQuot = false; boolean isSlash = false; - boolean isCComment=false; - boolean isCPPComment=false; + boolean isCComment = false; + boolean isCPPComment = false; boolean isRegex = false; boolean isOper = false; @@ -201,32 +206,36 @@ public class JsniBundleGenerator extends Generator { Character last = 0; Character prev = 0; - for (int i = 0, l = js.length(); i < l ; i++) { + for (int i = 0, l = js.length(); i < l; i++) { Character c = js.charAt(i); String out = c.toString(); if (isJS) { isDblQuot = c == '"'; - isSingQuot = c == '\''; - isSlash = c == '/'; - isJS = !isDblQuot && !isSingQuot && !isSlash; + isSingQuot = c == '\''; + isSlash = c == '/'; + isJS = !isDblQuot && !isSingQuot && !isSlash; if (!isJS) { out = tmp = ""; isCPPComment = isCComment = isRegex = false; } } else if (isSingQuot) { isJS = !(isSingQuot = last == '\\' || c != '\''); - if (isJS) out = escapeQuotedString(tmp, c); - else tmp += c; + if (isJS) + out = escapeQuotedString(tmp, c); + else + tmp += c; } else if (isDblQuot) { isJS = !(isDblQuot = last == '\\' || c != '"'); - if (isJS) out = escapeQuotedString(tmp, c); - else tmp += c; + if (isJS) + out = escapeQuotedString(tmp, c); + else + tmp += c; } else if (isSlash) { if (!isCPPComment && !isCComment && !isRegex && !isOper) { isCPPComment = c == '/'; - isCComment = c == '*'; - isOper = !isCPPComment && !isCComment && !"=(&|?:;},".contains(""+prev); + isCComment = c == '*'; + isOper = !isCPPComment && !isCComment && !"=(&|?:;},".contains("" + prev); isRegex = !isCPPComment && !isCComment && !isOper; } if (isOper) { @@ -234,18 +243,22 @@ public class JsniBundleGenerator extends Generator { out = "" + last + c; } else if (isCPPComment) { isJS = !(isSlash = isCPPComment = c != '\n'); - if (isJS) out = "\n"; + if (isJS) + out = "\n"; } else if (isCComment) { isSlash = isCComment = !(isJS = (last == '*' && c == '/')); - if (isJS) out = ""; + if (isJS) + out = ""; } else if (isRegex) { isJS = !(isSlash = isRegex = (last == '\\' || c != '/')); if (isJS) { String mod = ""; while (++i < l) { c = js.charAt(i); - if ("igm".contains(""+c)) mod += c; - else break; + if ("igm".contains("" + c)) + mod += c; + else + break; } out = escapeInlineRegex(tmp, mod) + c; } else { @@ -273,7 +286,7 @@ public class JsniBundleGenerator extends Generator { private String escapeInlineRegex(String s, String mod) { if (s.endsWith("*")) { - return "new RegExp('" + s.replace("\\", "\\\\") + "','" + mod + "')"; + return "new RegExp('" + s.replace("\\", "\\\\") + "','" + mod + "')"; } else { return '/' + s + '/' + mod; } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/JsonBuilderGenerator.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/JsonBuilderGenerator.java index 197e23b8..08e40c24 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/JsonBuilderGenerator.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/JsonBuilderGenerator.java @@ -15,14 +15,6 @@ */ package com.google.gwt.query.rebind; -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.core.ext.Generator; import com.google.gwt.core.ext.GeneratorContext; @@ -37,8 +29,8 @@ import com.google.gwt.core.ext.typeinfo.JParameterizedType; import com.google.gwt.core.ext.typeinfo.JType; import com.google.gwt.core.ext.typeinfo.TypeOracle; import com.google.gwt.query.client.Function; -import com.google.gwt.query.client.Properties; import com.google.gwt.query.client.IsProperties; +import com.google.gwt.query.client.Properties; import com.google.gwt.query.client.builders.JsonBuilder; import com.google.gwt.query.client.builders.JsonBuilderBase; import com.google.gwt.query.client.builders.JsonFactory; @@ -47,6 +39,14 @@ import com.google.gwt.query.client.js.JsUtils; import com.google.gwt.user.rebind.ClassSourceFileComposerFactory; import com.google.gwt.user.rebind.SourceWriter; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + /** */ public class JsonBuilderGenerator extends Generator { @@ -59,7 +59,6 @@ public class JsonBuilderGenerator extends Generator { static JClassType stringType; static JClassType jsonFactoryType; - public static String capitalize(String s) { if (s.length() == 0) return s; @@ -72,7 +71,7 @@ public class JsonBuilderGenerator extends Generator { public static String deCapitalize(String s) { return s == null || s.isEmpty() ? s : - (s.substring(0, 1).toLowerCase() + (s.length() > 1 ? s.substring(1) : "")); + (s.substring(0, 1).toLowerCase() + (s.length() > 1 ? s.substring(1) : "")); } TypeOracle oracle; @@ -82,7 +81,7 @@ public class JsonBuilderGenerator extends Generator { throws UnableToCompleteException { oracle = generatorContext.getTypeOracle(); - JClassType clazz = oracle.findType(requestedClass); + JClassType clazz = oracle.findType(requestedClass); jsonBuilderType = oracle.findType(JsonBuilder.class.getName()); settingsType = oracle.findType(IsProperties.class.getName()); @@ -96,7 +95,8 @@ public class JsonBuilderGenerator extends Generator { boolean isFactory = clazz.isAssignableTo(jsonFactoryType); - SourceWriter sw = getSourceWriter(treeLogger, generatorContext, t[0], t[1], isFactory, requestedClass); + SourceWriter sw = + getSourceWriter(treeLogger, generatorContext, t[0], t[1], isFactory, requestedClass); if (sw != null) { if (isFactory) { generateCreateMethod(sw, treeLogger); @@ -104,16 +104,16 @@ public class JsonBuilderGenerator extends Generator { Set<String> attrs = new HashSet<String>(); for (JMethod method : clazz.getInheritableMethods()) { String methName = method.getName(); - //skip method from JsonBuilder - if(jsonBuilderType.findMethod(method.getName(), method.getParameterTypes()) != null || - settingsType.findMethod(method.getName(), method.getParameterTypes()) != null ) { + // skip method from JsonBuilder + if (jsonBuilderType.findMethod(method.getName(), method.getParameterTypes()) != null || + settingsType.findMethod(method.getName(), method.getParameterTypes()) != null) { continue; } Name nameAnnotation = method.getAnnotation(Name.class); String name = nameAnnotation != null - ? nameAnnotation.value() - : methName.replaceFirst("^(get|set)", ""); + ? nameAnnotation.value() + : methName.replaceFirst("^(get|set)", ""); if (nameAnnotation == null) { name = name.substring(0, 1).toLowerCase() + name.substring(1); } @@ -170,15 +170,15 @@ public class JsonBuilderGenerator extends Generator { } else if (retType.equals("java.lang.Byte")) { sw.println("return (byte) p.getFloat(\"" + name + "\");"); } else if (retType.equals("java.lang.Integer")) { - sw.println("return (int) p.getFloat(\"" + name + "\");"); + sw.println("return (int) p.getFloat(\"" + name + "\");"); } else if (retType.equals("java.lang.Float")) { - sw.println("return p.getFloat(\"" + name + "\");"); + sw.println("return p.getFloat(\"" + name + "\");"); } else if (retType.equals("java.lang.Double")) { - sw.println("return (double) p.getFloat(\"" + name + "\");"); + sw.println("return (double) p.getFloat(\"" + name + "\");"); } else if (retType.equals("java.lang.Long")) { - sw.println("return (long) p.getFloat(\"" + name + "\");"); + sw.println("return (long) p.getFloat(\"" + name + "\");"); } else if (retType.equals("java.lang.Byte")) { - sw.println("return (byte) p.getFloat(\"" + name + "\");"); + sw.println("return (byte) p.getFloat(\"" + name + "\");"); } else if (isTypeAssignableTo(method.getReturnType(), stringType)) { sw.println("return p.getStr(\"" + name + "\");"); } else if (isTypeAssignableTo(method.getReturnType(), jsonBuilderType)) { @@ -221,8 +221,9 @@ public class JsonBuilderGenerator extends Generator { } else { sw.println("return Arrays.asList(" + ret + ");"); } - } else if (method.getReturnType().isEnum() != null){ - sw.println("return "+ method.getReturnType().getQualifiedSourceName() + ".valueOf(p.getStr(\"" + name + "\"));"); + } else if (method.getReturnType().isEnum() != null) { + sw.println("return " + method.getReturnType().getQualifiedSourceName() + + ".valueOf(p.getStr(\"" + name + "\"));"); } else { sw.println("System.err.println(\"JsonBuilderGenerator WARN: unknown return type " + retType + " " + ifaceName + "." + name + "()\"); "); @@ -248,15 +249,19 @@ public class JsonBuilderGenerator extends Generator { sw.println("setArrayBase(\"" + name + "\", " + a + ");"); } else if (type.getParameterizedQualifiedSourceName().matches("java.util.Date")) { sw.println("p.setNumber(\"" + name + "\", a.getTime());"); - } else if (type.getParameterizedQualifiedSourceName().matches("(java.lang.(Character|Long|Double|Integer|Float|Byte)|(char|long|double|int|float|byte))")) { + } else if (type + .getParameterizedQualifiedSourceName() + .matches( + "(java.lang.(Character|Long|Double|Integer|Float|Byte)|(char|long|double|int|float|byte))")) { sw.println("p.setNumber(\"" + name + "\", a);"); } else if (type.getParameterizedQualifiedSourceName().matches("(java.lang.Boolean|boolean)")) { sw.println("p.setBoolean(\"" + name + "\", a);"); - } else if (type.getParameterizedQualifiedSourceName().matches("com.google.gwt.query.client.Function")) { + } else if (type.getParameterizedQualifiedSourceName().matches( + "com.google.gwt.query.client.Function")) { sw.println("p.setFunction(\"" + name + "\", a);"); - } else if (type.isEnum() != null){ + } else if (type.isEnum() != null) { sw.println("p.set(\"" + name + "\", a.name());"); - }else { + } else { sw.println("set(\"" + name + "\", a);"); } if (!"void".equals(retType)) { @@ -311,9 +316,10 @@ public class JsonBuilderGenerator extends Generator { sw.indent(); ArrayList<JClassType> types = new ArrayList<JClassType>(); for (JClassType t : oracle.getTypes()) { - if (t.isInterface() != null && t.isAssignableTo(jsonBuilderType) ) { + if (t.isInterface() != null && t.isAssignableTo(jsonBuilderType)) { if (t.isPublic()) { - sw.println("if (clz == " + t.getQualifiedSourceName() + ".class) return GWT.<T>create(" + t.getQualifiedSourceName() + ".class);"); + sw.println("if (clz == " + t.getQualifiedSourceName() + ".class) return GWT.<T>create(" + + t.getQualifiedSourceName() + ".class);"); } else { logger.log(Type.WARN, t.getQualifiedSourceName() + " is not public"); } @@ -325,7 +331,8 @@ public class JsonBuilderGenerator extends Generator { sw.println("}"); sw.println("public " + IsProperties.class.getName() + " create(String s) {"); sw.indent(); - sw.println("return (" + IsProperties.class.getName() + ")" + JsUtils.class.getName() + ".parseJSON(s);"); + sw.println("return (" + IsProperties.class.getName() + ")" + JsUtils.class.getName() + + ".parseJSON(s);"); sw.outdent(); sw.println("}"); sw.println("public " + IsProperties.class.getName() + " create() {"); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/LazyGenerator.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/LazyGenerator.java index 1ad4c850..0a2cce56 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/LazyGenerator.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/LazyGenerator.java @@ -63,8 +63,9 @@ public class LazyGenerator extends Generator { break; } } - - if (targetType == null) return null; + + if (targetType == null) + return null; assert targetType != null : "Parameter of Lazy<T> not found"; String genClass = targetType.getPackage().getName() + "." @@ -173,8 +174,8 @@ public class LazyGenerator extends Generator { if (printWriter == null) { return null; } - ClassSourceFileComposerFactory composerFactory - = new ClassSourceFileComposerFactory(packageName, className); + ClassSourceFileComposerFactory composerFactory = + new ClassSourceFileComposerFactory(packageName, className); composerFactory.addImport("com.google.gwt.core.client.*"); composerFactory.addImport("com.google.gwt.query.client.*"); composerFactory.addImport("com.google.gwt.dom.client.Element"); @@ -207,7 +208,7 @@ public class LazyGenerator extends Generator { sw.println( "ctx = GQuery.$(getElement()).as(" + nonLazyType.getQualifiedSourceName() + "." - + classID + ");"); + + classID + ");"); sw.println("for (int i = 0; i < closures.length(); i++) {"); sw.indent(); sw.println("closures.get(i).invoke();"); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorBase.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorBase.java index d2aff311..515f6444 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorBase.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorBase.java @@ -193,9 +193,9 @@ public abstract class SelectorGeneratorBase extends Generator { + "\"; }"); sw .println("public NodeList<Element> runSelector(Node ctx) { return " + - (m.getName() + (m.getParameters().length == 0 ? "()" : "(ctx)")) + - ("NodeList".equals(m.getReturnType().getSimpleSourceName()) ? "" : ".get()") + ";}" - ) ; + (m.getName() + (m.getParameters().length == 0 ? "()" : "(ctx)")) + + ("NodeList".equals(m.getReturnType().getSimpleSourceName()) ? "" : ".get()") + ";}" + ); sw.outdent(); sw.println("},"); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorCssToXPath.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorCssToXPath.java index 45b1a848..1590b2c0 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorCssToXPath.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorCssToXPath.java @@ -15,15 +15,6 @@ */ package com.google.gwt.query.rebind; -import java.util.ArrayList; -import java.util.regex.MatchResult; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathExpressionException; -import javax.xml.xpath.XPathFactory; - import com.google.gwt.core.ext.TreeLogger; import com.google.gwt.core.ext.UnableToCompleteException; import com.google.gwt.core.ext.typeinfo.JMethod; @@ -33,6 +24,15 @@ import com.google.gwt.query.client.impl.SelectorEngineCssToXPath.ReplaceCallback import com.google.gwt.query.client.impl.SelectorEngineCssToXPath.Replacer; import com.google.gwt.user.rebind.SourceWriter; +import java.util.ArrayList; +import java.util.regex.MatchResult; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + /** * Compile time selector generator which translates selector into XPath at * compile time. It Uses the SelectorEngineCssToXpath to produce the xpath @@ -90,8 +90,9 @@ public class SelectorGeneratorCssToXPath extends SelectorGeneratorBase { } catch (XPathExpressionException e1) { System.err.println("Invalid XPath generated selector, please revise it: " + xselector); if (!selector.equals(xselector)) { - System.err.println("If your css2 selector syntax is correct, open an issue in the gwtquery project. cssselector:" - + selector + " xpath:" + xselector); + System.err + .println("If your css2 selector syntax is correct, open an issue in the gwtquery project. cssselector:" + + selector + " xpath: " + xselector); } throw new UnableToCompleteException(); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorJSOptimal.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorJSOptimal.java index 7cbdcf13..81dcc0a3 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorJSOptimal.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorJSOptimal.java @@ -58,7 +58,7 @@ public class SelectorGeneratorJSOptimal extends SelectorGeneratorBase { protected static Pattern nthRe2 = Pattern.compile("\\D"); - protected static RuleMatcher[] matchers = new RuleMatcher[]{ + protected static RuleMatcher[] matchers = new RuleMatcher[] { new RuleMatcher("^\\.([a-zA-Z_0-9-]+)", "n = byClassName(n, null, \"{0}\");"), new RuleMatcher("^\\:([a-zA-Z_0-9-]+)(?:\\(((?:[^ >]*|.*?))\\))?", @@ -75,112 +75,112 @@ public class SelectorGeneratorJSOptimal extends SelectorGeneratorBase { sw.println("return " + wrap(method, "impl.select(\"" + selector + "\", root)") + ";"); -// sw.println("JSArray n = JSArray.create();"); -// if(!hasContext) { -// sw.println("Node root = Document.get();"); -// } -// -// // add root node as context. -// // TODO: support any context -// sw.println("n.addNode(root);"); -// String q = selector, lq = null; -// Matcher lmode = modeRe.matcher(q); -// Matcher mm = null; -// String mode = ""; -// if (lmode.lookingAt() && notNull(lmode.group(1))) { -// mode = lmode.group(1).replaceAll(trimReStr, "").trim(); -// q = q.replaceFirst("\\Q" + lmode.group(1) + "\\E", ""); -// } -// -// while (notNull(q) && !q.equals(lq)) { -// debug("Doing q=" + q); -// -// lq = q; -// Matcher tm = tagTokenRe.matcher(q); -// if (tm.lookingAt()) { -// if ("#".equals(tm.group(1))) { -// sw.println("n = quickId(n, \"" + mode + "\", root, \"" + tm.group(2) -// + "\");"); -// } else { -// String tagName = tm.group(2); -// tagName = "".equals(tagName) ? "*" : tagName; -// // sw.println("if (n.size() == 0) { n=JSArray.create(); }"); -// String func = ""; -// if ("".equals(mode)) { -// func = "getDescendentNodes"; -// } else if (">".equals(mode)) { -// func = "getChildNodes"; -// } else if ("+".equals(mode)) { -// func = "getSiblingNodes"; -// } else if ("~".equals(mode)) { -// func = "getGeneralSiblingNodes"; -// } else { -// treeLogger.log(TreeLogger.ERROR, "Error parsing selector, combiner " -// + mode + " not recognized in " + selector, null); -// throw new UnableToCompleteException(); -// } -// sw.println("n = " + func + "(n, \"" + tagName + "\");"); -// } -// debug("replacing in q, the value " + tm.group(0)); -// q = q.replaceFirst("\\Q" + tm.group(0) + "\\E", ""); -// } else { -// String func = ""; -// String tagName = "*"; -// if ("".equals(mode)) { -// func = "getDescendentNodes"; -// } else if (">".equals(mode)) { -// func = "getChildNodes"; -// } else if ("+".equals(mode)) { -// func = "getSiblingNodes"; -// } else if ("~".equals(mode)) { -// func = "getGeneralSiblingNodes"; -// } else { -// treeLogger.log(TreeLogger.ERROR, "Error parsing selector, combiner " -// + mode + " not recognized in " + selector, null); -// throw new UnableToCompleteException(); -// } -// sw.println("n = " + func + "(n, \"" + tagName + "\");"); -// } -// -// while (!(mm = modeRe.matcher(q)).lookingAt()) { -// debug("Looking at " + q); -// boolean matched = false; -// for (RuleMatcher rm : matchers) { -// Matcher rmm = rm.re.matcher(q); -// if (rmm.lookingAt()) { -// String res[] = new String[rmm.groupCount()]; -// for (int i = 1; i <= rmm.groupCount(); i++) { -// res[i - 1] = rmm.group(i); -// debug("added param " + res[i - 1]); -// } -// Object[] r = res; -// // inline enum, perhaps type-tightening will allow inlined eval() -// // call -// if (rm.fnTemplate.indexOf("byPseudo") != -1) { -// sw.println("n = Pseudo."+res[0].toUpperCase().replace("-", "_") + -// ".eval(n, \""+res[1]+"\");"); -// } else { -// sw.println(MessageFormat.format(rm.fnTemplate, r)); -// } -// q = q.replaceFirst("\\Q" + rmm.group(0) + "\\E", ""); -// matched = true; -// break; -// } -// } -// if (!matched) { -// treeLogger -// .log(TreeLogger.ERROR, "Error parsing selector at " + q, null); -// throw new UnableToCompleteException(); -// } -// } -// -// if (notNull(mm.group(1))) { -// mode = mm.group(1).replaceAll(trimReStr, ""); -// debug("replacing q=" + q + " this part:" + mm.group(1)); -// q = q.replaceFirst("\\Q" + mm.group(1) + "\\E", ""); -// } -// } -// sw.println("return "+wrap(method, "nodup(n)")+";"); + // sw.println("JSArray n = JSArray.create();"); + // if(!hasContext) { + // sw.println("Node root = Document.get();"); + // } + // + // // add root node as context. + // // TODO: support any context + // sw.println("n.addNode(root);"); + // String q = selector, lq = null; + // Matcher lmode = modeRe.matcher(q); + // Matcher mm = null; + // String mode = ""; + // if (lmode.lookingAt() && notNull(lmode.group(1))) { + // mode = lmode.group(1).replaceAll(trimReStr, "").trim(); + // q = q.replaceFirst("\\Q" + lmode.group(1) + "\\E", ""); + // } + // + // while (notNull(q) && !q.equals(lq)) { + // debug("Doing q=" + q); + // + // lq = q; + // Matcher tm = tagTokenRe.matcher(q); + // if (tm.lookingAt()) { + // if ("#".equals(tm.group(1))) { + // sw.println("n = quickId(n, \"" + mode + "\", root, \"" + tm.group(2) + // + "\");"); + // } else { + // String tagName = tm.group(2); + // tagName = "".equals(tagName) ? "*" : tagName; + // // sw.println("if (n.size() == 0) { n=JSArray.create(); }"); + // String func = ""; + // if ("".equals(mode)) { + // func = "getDescendentNodes"; + // } else if (">".equals(mode)) { + // func = "getChildNodes"; + // } else if ("+".equals(mode)) { + // func = "getSiblingNodes"; + // } else if ("~".equals(mode)) { + // func = "getGeneralSiblingNodes"; + // } else { + // treeLogger.log(TreeLogger.ERROR, "Error parsing selector, combiner " + // + mode + " not recognized in " + selector, null); + // throw new UnableToCompleteException(); + // } + // sw.println("n = " + func + "(n, \"" + tagName + "\");"); + // } + // debug("replacing in q, the value " + tm.group(0)); + // q = q.replaceFirst("\\Q" + tm.group(0) + "\\E", ""); + // } else { + // String func = ""; + // String tagName = "*"; + // if ("".equals(mode)) { + // func = "getDescendentNodes"; + // } else if (">".equals(mode)) { + // func = "getChildNodes"; + // } else if ("+".equals(mode)) { + // func = "getSiblingNodes"; + // } else if ("~".equals(mode)) { + // func = "getGeneralSiblingNodes"; + // } else { + // treeLogger.log(TreeLogger.ERROR, "Error parsing selector, combiner " + // + mode + " not recognized in " + selector, null); + // throw new UnableToCompleteException(); + // } + // sw.println("n = " + func + "(n, \"" + tagName + "\");"); + // } + // + // while (!(mm = modeRe.matcher(q)).lookingAt()) { + // debug("Looking at " + q); + // boolean matched = false; + // for (RuleMatcher rm : matchers) { + // Matcher rmm = rm.re.matcher(q); + // if (rmm.lookingAt()) { + // String res[] = new String[rmm.groupCount()]; + // for (int i = 1; i <= rmm.groupCount(); i++) { + // res[i - 1] = rmm.group(i); + // debug("added param " + res[i - 1]); + // } + // Object[] r = res; + // // inline enum, perhaps type-tightening will allow inlined eval() + // // call + // if (rm.fnTemplate.indexOf("byPseudo") != -1) { + // sw.println("n = Pseudo."+res[0].toUpperCase().replace("-", "_") + + // ".eval(n, \""+res[1]+"\");"); + // } else { + // sw.println(MessageFormat.format(rm.fnTemplate, r)); + // } + // q = q.replaceFirst("\\Q" + rmm.group(0) + "\\E", ""); + // matched = true; + // break; + // } + // } + // if (!matched) { + // treeLogger + // .log(TreeLogger.ERROR, "Error parsing selector at " + q, null); + // throw new UnableToCompleteException(); + // } + // } + // + // if (notNull(mm.group(1))) { + // mode = mm.group(1).replaceAll(trimReStr, ""); + // debug("replacing q=" + q + " this part: " + mm.group(1)); + // q = q.replaceFirst("\\Q" + mm.group(1) + "\\E", ""); + // } + // } + // sw.println("return "+wrap(method, "nodup(n)")+";"); } protected String getImplSuffix() { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNative.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNative.java index 459df9af..5624a0b0 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNative.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNative.java @@ -45,8 +45,8 @@ public class SelectorGeneratorNative extends SelectorGeneratorCssToXPath { } else if (selector.contains("!=")) { sw.println("return " + wrap(method, "querySelectorAll(\"" - + selector.replaceAll("(\\[\\w+)!(=[^\\]]+\\])", ":not($1$2)") - + "\", root)") + ";"); + + selector.replaceAll("(\\[\\w+)!(=[^\\]]+\\])", ":not($1$2)") + + "\", root)") + ";"); } else if (selector.matches(SelectorEngineNative.NATIVE_EXCEPTIONS_REGEXP)) { super.generateMethodBody(sw, method, treeLogger, hasContext); } else { @@ -64,4 +64,4 @@ public class SelectorGeneratorNative extends SelectorGeneratorCssToXPath { protected boolean hasGetElementsByClassName() { return true; } -}
\ No newline at end of file +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNativeIE8.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNativeIE8.java index 2aa28946..3fe445c5 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNativeIE8.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNativeIE8.java @@ -58,4 +58,4 @@ public class SelectorGeneratorNativeIE8 extends SelectorGeneratorJS { protected boolean hasGetElementsByClassName() { return false; } -}
\ No newline at end of file +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNativeIE9.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNativeIE9.java index 899886ae..aac00fdf 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNativeIE9.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorNativeIE9.java @@ -58,4 +58,4 @@ public class SelectorGeneratorNativeIE9 extends SelectorGeneratorJS { protected boolean hasGetElementsByClassName() { return false; } -}
\ No newline at end of file +} diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorXPath.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorXPath.java index fdc4838c..ad11c989 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorXPath.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorXPath.java @@ -57,8 +57,10 @@ public class SelectorGeneratorXPath extends SelectorGeneratorBase { public String tagRelation; } - private static Pattern cssSelectorRegExp = Pattern.compile( - "^(\\w+)?(#[a-zA-Z_0-9\u00C0-\uFFFF\\-\\_]+|(\\*))?((\\.[a-zA-Z_0-9\u00C0-\uFFFF\\-_]+)*)?((\\[\\w+(\\^|\\$|\\*|\\||~)?(=[a-zA-Z_0-9\u00C0-\uFFFF\\s\\-\\_\\.]+)?\\]+)*)?(((:\\w+[a-zA-Z_0-9\\-]*)(\\((odd|even|\\-?\\d*n?((\\+|\\-)\\d+)?|[a-zA-Z_0-9\u00C0-\uFFFF\\-_]+|((\\w*\\.[a-zA-Z_0-9\u00C0-\uFFFF\\-_]+)*)?|(\\[#?\\w+(\\^|\\$|\\*|\\||~)?=?[a-zA-Z_0-9\u00C0-\uFFFF\\s\\-\\_\\.]+\\]+)|(:\\w+[a-zA-Z_0-9\\-]*))\\))?)*)?(>|\\+|~)?"); + private static Pattern cssSelectorRegExp = + Pattern + .compile( + "^(\\w+)?(#[a-zA-Z_0-9\u00C0-\uFFFF\\-\\_]+|(\\*))?((\\.[a-zA-Z_0-9\u00C0-\uFFFF\\-_]+)*)?((\\[\\w+(\\^|\\$|\\*|\\||~)?(=[a-zA-Z_0-9\u00C0-\uFFFF\\s\\-\\_\\.]+)?\\]+)*)?(((:\\w+[a-zA-Z_0-9\\-]*)(\\((odd|even|\\-?\\d*n?((\\+|\\-)\\d+)?|[a-zA-Z_0-9\u00C0-\uFFFF\\-_]+|((\\w*\\.[a-zA-Z_0-9\u00C0-\uFFFF\\-_]+)*)?|(\\[#?\\w+(\\^|\\$|\\*|\\||~)?=?[a-zA-Z_0-9\u00C0-\uFFFF\\s\\-\\_\\.]+\\]+)|(:\\w+[a-zA-Z_0-9\\-]*))\\))?)*)?(>|\\+|~)?"); private static Pattern selectorSplitRegExp = Pattern .compile("(?:\\[[^\\[]*\\]|\\(.*\\)|[^\\s\\+>~\\[\\(])+|[\\+>~]"); @@ -227,20 +229,22 @@ public class SelectorGeneratorXPath extends SelectorGeneratorBase { private Sequence getSequence(String expression) { int start = 0, add = 2, max = -1, modVal = -1; - Pattern expressionRegExp = Pattern.compile( - "^((odd|even)|([1-9]\\d*)|((([1-9]\\d*)?)n([\\+\\-]\\d+)?)|(\\-(([1-9]\\d*)?)n\\+(\\d+)))$"); + Pattern expressionRegExp = + Pattern + .compile( + "^((odd|even)|([1-9]\\d*)|((([1-9]\\d*)?)n([\\+\\-]\\d+)?)|(\\-(([1-9]\\d*)?)n\\+(\\d+)))$"); Matcher pseudoValue = expressionRegExp.matcher(expression); if (!pseudoValue.matches()) { return null; } else { - if (notNull(pseudoValue.group(2))) { // odd or even + if (notNull(pseudoValue.group(2))) { // odd or even start = ("odd".equals(pseudoValue.group(2))) ? 1 : 2; modVal = (start == 1) ? 1 : 0; - } else if (notNull(pseudoValue.group(3))) { // single digit + } else if (notNull(pseudoValue.group(3))) { // single digit start = Integer.parseInt(pseudoValue.group(3), 10); add = 0; max = start; - } else if (notNull(pseudoValue.group(4))) { // an+b + } else if (notNull(pseudoValue.group(4))) { // an+b add = notNull(pseudoValue.group(6)) ? getInt(pseudoValue.group(6), 1) : 1; start = notNull(pseudoValue.group(7)) ? getInt(pseudoValue.group(7), 0) @@ -250,7 +254,7 @@ public class SelectorGeneratorXPath extends SelectorGeneratorBase { } modVal = (start > add) ? (start - add) % add : ((start == add) ? 0 : start); - } else if (notNull(pseudoValue.group(8))) { // -an+b + } else if (notNull(pseudoValue.group(8))) { // -an+b add = notNull(pseudoValue.group(10)) ? Integer .parseInt(pseudoValue.group(10), 10) : 1; start = max = Integer.parseInt(pseudoValue.group(10), 10); @@ -292,8 +296,8 @@ public class SelectorGeneratorXPath extends SelectorGeneratorBase { } else { xpath = position + " mod " + sequence.add + " = " + sequence.modVal + ((sequence.start > 1) ? " and " + position + " >= " - + sequence.start : "") + ((sequence.max > 0) ? " and " - + position + " <= " + sequence.max : ""); + + sequence.start : "") + ((sequence.max > 0) ? " and " + + position + " <= " + sequence.max : ""); } } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/XmlBuilderGenerator.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/XmlBuilderGenerator.java index e643ecc1..d68af817 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/XmlBuilderGenerator.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/XmlBuilderGenerator.java @@ -15,8 +15,6 @@ */ package com.google.gwt.query.rebind; -import java.io.PrintWriter; - import com.google.gwt.core.ext.Generator; import com.google.gwt.core.ext.GeneratorContext; import com.google.gwt.core.ext.TreeLogger; @@ -33,6 +31,8 @@ import com.google.gwt.query.client.builders.XmlBuilder; import com.google.gwt.user.rebind.ClassSourceFileComposerFactory; import com.google.gwt.user.rebind.SourceWriter; +import java.io.PrintWriter; + /** */ public class XmlBuilderGenerator extends Generator { @@ -54,9 +54,9 @@ public class XmlBuilderGenerator extends Generator { t[1], requestedClass); if (sw != null) { for (JMethod method : clazz.getInheritableMethods()) { - //skip method from JsonBuilder - if(xmlBuilderType.findMethod(method.getName(), method.getParameterTypes()) != null){ - continue; + // skip method from JsonBuilder + if (xmlBuilderType.findMethod(method.getName(), method.getParameterTypes()) != null) { + continue; } generateMethod(sw, method, treeLogger); } @@ -106,12 +106,13 @@ public class XmlBuilderGenerator extends Generator { } else if (isTypeAssignableTo(method.getReturnType(), xmlBuilderType)) { String q = method.getReturnType().getQualifiedSourceName(); sw.println("Element e = getElementBase(\"" + name + "\");"); - sw.println("return e == null ? null : (" + q + ")((" + q + ")GWT.create(" + q + ".class)).load(e);"); - } else if (retType.equals(Properties.class.getName())){ + sw.println("return e == null ? null : (" + q + ")((" + q + ")GWT.create(" + q + + ".class)).load(e);"); + } else if (retType.equals(Properties.class.getName())) { sw.println("return getPropertiesBase(\"" + name + "\");"); } else if (arr != null) { String q = arr.getComponentType().getQualifiedSourceName(); - sw.println("ArrayList<" + q + "> l = new ArrayList<" + q+ ">();"); + sw.println("ArrayList<" + q + "> l = new ArrayList<" + q + ">();"); sw.println("for (Element e: getElementsBase(\"" + name + "\")) {"); sw.println(" " + q + " c = GWT.create(" + q + ".class);"); sw.println(" c.load(e);"); @@ -135,7 +136,7 @@ public class XmlBuilderGenerator extends Generator { } else { sw.println("setBase(\"" + name + "\", a);"); } - if (!"void".equals(retType)){ + if (!"void".equals(retType)) { if (isTypeAssignableTo(method.getReturnType(), method.getEnclosingType())) { sw.println("return this;"); } else { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/vm/AjaxTransportJre.java b/gwtquery-core/src/main/java/com/google/gwt/query/vm/AjaxTransportJre.java index 2db50517..fa756933 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/vm/AjaxTransportJre.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/vm/AjaxTransportJre.java @@ -1,85 +1,101 @@ +/* + * Copyright 2014, The gwtquery team. + * + * 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.gwt.query.vm; // import org.apache.http.impl.client.HttpClientBuilder; -import java.io.BufferedReader; -import java.io.DataOutputStream; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.URL; - import com.google.gwt.http.client.RequestException; import com.google.gwt.http.client.Response; -import com.google.gwt.query.client.IsProperties; import com.google.gwt.query.client.Function; import com.google.gwt.query.client.GQ; import com.google.gwt.query.client.GQuery; +import com.google.gwt.query.client.IsProperties; import com.google.gwt.query.client.Promise; import com.google.gwt.query.client.plugins.ajax.Ajax.AjaxTransport; import com.google.gwt.query.client.plugins.ajax.Ajax.Settings; import com.google.gwt.query.client.plugins.deferred.PromiseFunction; import com.google.gwt.user.server.Base64Utils; +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + /** * */ public class AjaxTransportJre implements AjaxTransport { - + private static String localDomain = null; - + private static CookieManager cookieManager = CookieManager.getInstance(); private static boolean debugOutput = false; - + private static boolean followRedirections = true; - + public static void enableCORS(String domain) { localDomain = domain; System.setProperty("sun.net.http.allowRestrictedHeaders", "true"); } - + public static void enableDebug(boolean b) { debugOutput = b; } - + public static void enableCookies(boolean b) { cookieManager = b ? CookieManager.getInstance() : null; } - + public static void enableRedirections(boolean b) { followRedirections = b; } - - private final String USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:26.0) Gecko/20100101 Firefox/26.0"; + + private static final String USER_AGENT = + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:26.0) Gecko/20100101 Firefox/26.0"; private final String jsonpCbRexp = "(?ms)^.*jre_callback\\((.*)\\).*$"; public Promise getJsonP(final Settings settings) { String url = settings.getUrl().replaceFirst("callback=[^&]*", ""); url += (url.contains("?") ? "&" : "?") + "callback=jre_callback"; settings.setUrl(url); - + if (settings.getTimeout() < 1) { settings.setTimeout(10000); } - + return getXhr(settings, false) - .then(new Function() { - public Object f(Object... args) { - Response response = arguments(0); - if (response.getText().matches(jsonpCbRexp)) { - return GQ.create(response.getText().replaceFirst(jsonpCbRexp, "$1")); - } else { - return GQuery.Deferred().reject().promise(); + .then(new Function() { + public Object f(Object... args) { + Response response = arguments(0); + if (response.getText().matches(jsonpCbRexp)) { + return GQ.create(response.getText().replaceFirst(jsonpCbRexp, "$1")); + } else { + return GQuery.Deferred().reject().promise(); + } } - } - }); + }); } public Promise getLoadScript(Settings settings) { return getXhr(settings, false); } - + public Promise getXhr(final Settings settings) { return getXhr(settings, true); } @@ -92,7 +108,8 @@ public class AjaxTransportJre implements AjaxTransport { int status = response.getStatusCode(); if (status <= 0 || status >= 400) { String statusText = status <= 0 ? "Bad CORS" : response.getStatusText(); - dfd.reject(new RequestException("HTTP ERROR: " + status + " " + statusText + "\n" + response.getText()), null); + dfd.reject(new RequestException("HTTP ERROR: " + status + " " + statusText + "\n" + + response.getText()), null); } else { dfd.resolve(response, null); } @@ -107,21 +124,22 @@ public class AjaxTransportJre implements AjaxTransport { private Response httpClient(Settings s, boolean cors) throws Exception { String url = s.getUrl(); assert url.toLowerCase().startsWith("http"); - + URL u = new URL(url); HttpURLConnection c = (HttpURLConnection) u.openConnection(); - + c.setInstanceFollowRedirects(followRedirections); - + c.setRequestMethod(s.getType()); c.setRequestProperty("User-Agent", USER_AGENT); if (s.getUsername() != null && s.getPassword() != null) { - c.setRequestProperty ("Authorization", "Basic " + Base64Utils.toBase64((s.getUsername() + ":" + s.getPassword()).getBytes())); + c.setRequestProperty("Authorization", "Basic " + + Base64Utils.toBase64((s.getUsername() + ":" + s.getPassword()).getBytes())); } if (cookieManager != null) { cookieManager.setCookies(c); } - + boolean isCORS = cors && localDomain != null && !s.getUrl().contains(localDomain); if (isCORS) { // TODO: fetch options previously to the request @@ -141,24 +159,24 @@ public class AjaxTransportJre implements AjaxTransport { // Access-Control-Allow-Credentials: true c.setRequestProperty("Origin", localDomain); } - + if (s.getTimeout() > 0) { c.setConnectTimeout(s.getTimeout()); c.setReadTimeout(s.getTimeout()); } - + IsProperties headers = s.getHeaders(); if (headers != null) { for (String h : headers.getFieldNames()) { c.setRequestProperty(h, "" + headers.get(h)); } } - + if (s.getType().matches("POST|PUT")) { c.setRequestProperty("Content-Type", s.getContentType()); - + debugRequest(c, s.getDataString()); - + c.setDoOutput(true); DataOutputStream wr = new DataOutputStream(c.getOutputStream()); wr.writeBytes(s.getDataString()); @@ -167,7 +185,7 @@ public class AjaxTransportJre implements AjaxTransport { } else { debugRequest(c, null); } - + int code = c.getResponseCode(); if (isCORS) { if (!localDomain.equals(c.getHeaderField("Access-Control-Allow-Origin"))) { @@ -177,9 +195,9 @@ public class AjaxTransportJre implements AjaxTransport { code = 0; } } - + String payload = ""; - + InputStream is = code >= 400 ? c.getErrorStream() : c.getInputStream(); if (is != null) { BufferedReader in = new BufferedReader(new InputStreamReader(is)); @@ -191,14 +209,14 @@ public class AjaxTransportJre implements AjaxTransport { in.close(); payload = response.toString(); } - + if (cookieManager != null) { cookieManager.storeCookies(c); } return new ResponseJre(code, c.getResponseMessage(), payload, c.getHeaderFields()); } - + private void debugRequest(HttpURLConnection c, String payload) { if (debugOutput) { System.out.println(c.getRequestMethod() + " " + c.getURL().getPath()); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/vm/CookieManager.java b/gwtquery-core/src/main/java/com/google/gwt/query/vm/CookieManager.java index 1f1241ba..0075b708 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/vm/CookieManager.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/vm/CookieManager.java @@ -1,3 +1,18 @@ +/* + * Copyright 2014, The gwtquery team. + * + * 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.gwt.query.vm; import java.io.IOException; @@ -12,12 +27,12 @@ import java.util.Map; import java.util.StringTokenizer; /** - * @author Ian Brown spam@hccp.org - * http://www.hccp.org/java-net-cookie-how-to.html + * http://www.hccp.org/java-net-cookie-how-to.html. */ public class CookieManager { - private Map<String,Map<String,Map<String, String>>> store = new HashMap<String, Map<String,Map<String, String>>>(); + private Map<String, Map<String, Map<String, String>>> store = + new HashMap<String, Map<String, Map<String, String>>>(); private static final String SET_COOKIE = "Set-Cookie"; private static final String COOKIE_VALUE_DELIMITER = ";"; @@ -31,39 +46,39 @@ public class CookieManager { private static final char DOT = '.'; private DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);; - + private static CookieManager cookieManager = new CookieManager(); public static CookieManager getInstance() { return cookieManager; } - + public void clear() { store.clear(); } - + public void removeDomainCookies(String domain) { store.remove(domain); } - + public void removeDomainCookie(String domain, String... cookies) { - Map<String, Map<String, String>> domainStore = store.get(domain); + Map<String, Map<String, String>> domainStore = store.get(domain); if (domainStore != null) { - for (String cookie: cookies) { + for (String cookie : cookies) { domainStore.remove(cookie); } } } - + public void setDomcainCookie(String host, String name, String value) { setDomcainCookieProperty(host, name, name, value); } - + public void setDomcainCookieProperty(String host, String name, String prop, String value) { String domain = getDomainFromHost(host); - Map<String, Map<String, String>> domainStore = store.get(domain); + Map<String, Map<String, String>> domainStore = store.get(domain); if (domainStore == null) { - domainStore = new HashMap<String, Map<String,String>>(); + domainStore = new HashMap<String, Map<String, String>>(); store.put(domain, domainStore); } Map<String, String> cookie = domainStore.get(name); @@ -92,7 +107,7 @@ public class CookieManager { // let's determine the domain from where these cookies are being sent String domain = getDomainFromHost(conn.getURL().getHost()); - Map<String,Map<String, String>> domainStore; // this is where we will store cookies for this domain + Map<String, Map<String, String>> domainStore; // this is where we will store cookies for this domain // now let's check the store to see if we have an entry for this domain if (store.containsKey(domain)) { @@ -100,7 +115,7 @@ public class CookieManager { domainStore = store.get(domain); } else { // we don't, so let's create it and put it in the store - domainStore = new HashMap<String, Map<String,String>>(); + domainStore = new HashMap<String, Map<String, String>>(); store.put(domain, domainStore); } @@ -127,8 +142,9 @@ public class CookieManager { while (st.hasMoreTokens()) { String token = st.nextToken().toLowerCase(); int idx = token.indexOf(NAME_VALUE_SEPARATOR); - if (idx > 0 && idx < token.length() -1) { - cookie.put(token.substring(0, idx).toLowerCase(), token.substring(idx + 1, token.length())); + if (idx > 0 && idx < token.length() - 1) { + cookie.put(token.substring(0, idx).toLowerCase(), token.substring(idx + 1, token + .length())); } } } @@ -154,7 +170,7 @@ public class CookieManager { } String path = url.getPath(); - Map<String, Map<String, String>> domainStore = store.get(domain); + Map<String, Map<String, String>> domainStore = store.get(domain); if (domainStore == null) return; StringBuffer cookieStringBuffer = new StringBuffer(); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/vm/JsonFactoryJre.java b/gwtquery-core/src/main/java/com/google/gwt/query/vm/JsonFactoryJre.java index 54e8aab3..66a8f5bc 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/vm/JsonFactoryJre.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/vm/JsonFactoryJre.java @@ -1,3 +1,18 @@ +/* + * Copyright 2014, The gwtquery team. + * + * 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.gwt.query.vm; import com.google.gwt.query.client.Function; @@ -17,7 +32,7 @@ import elemental.json.impl.JreJsonNull; * It uses java.util.reflect.Proxy to implement JsonBuilders * and elemental light weight json to handle json data. */ -public class JsonFactoryJre implements JsonFactory { +public class JsonFactoryJre implements JsonFactory { @@ -28,14 +43,17 @@ public class JsonFactoryJre implements JsonFactory { * Functions in JVM. */ static class JreJsonFunction extends JreJsonNull { - final private Function function; + private final Function function; + public JreJsonFunction(Function f) { function = f; } + @Override public String toJson() { return function.toString(); } + public Function getFunction() { return function; } @@ -55,12 +73,14 @@ public class JsonFactoryJre implements JsonFactory { public IsProperties createBinder() { InvocationHandler handler = new JsonBuilderHandler(); - return (IsProperties)Proxy.newProxyInstance(IsProperties.class.getClassLoader(), new Class[] {IsProperties.class}, handler); + return (IsProperties) Proxy.newProxyInstance(IsProperties.class.getClassLoader(), + new Class[] {IsProperties.class}, handler); } public IsProperties createBinder(JsonObject jso) { InvocationHandler handler = new JsonBuilderHandler(jso); - return (IsProperties)Proxy.newProxyInstance(IsProperties.class.getClassLoader(), new Class[] {IsProperties.class}, handler); + return (IsProperties) Proxy.newProxyInstance(IsProperties.class.getClassLoader(), + new Class[] {IsProperties.class}, handler); } @Override diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/vm/ResponseJre.java b/gwtquery-core/src/main/java/com/google/gwt/query/vm/ResponseJre.java index 207484a9..1aa8352c 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/vm/ResponseJre.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/vm/ResponseJre.java @@ -1,27 +1,42 @@ +/* + * Copyright 2014, The gwtquery team. + * + * 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.gwt.query.vm; -import java.util.List; -import java.util.Map; - import com.google.gwt.http.client.Header; import com.google.gwt.http.client.Response; +import java.util.List; +import java.util.Map; + /** - * Implementation of `Response` in the JVM + * Implementation of `Response` in the JVM. */ public class ResponseJre extends Response { private int status; - private Map<String,List<String>> headers; + private Map<String, List<String>> headers; private String responseText; private String statusText; - - public ResponseJre(int status, String statusText, String text, Map<String,List<String>> headers) { + + public ResponseJre(int status, String statusText, String text, Map<String, List<String>> headers) { this.status = status; this.headers = headers; this.responseText = text; this.statusText = statusText; } - + public String getHeader(String header) { List<String> l = headers.get(header); if (l != null && !l.isEmpty()) { @@ -43,6 +58,7 @@ public class ResponseJre extends Response { public String getValue() { return v; } + public String getName() { return s; } @@ -51,20 +67,24 @@ public class ResponseJre extends Response { } return ret; } + public String getHeadersAsString() { String ret = ""; for (Header h : getHeaders()) { - ret += h.getName() + ":" + h.getValue() + "\n"; + ret += h.getName() + ":" + h.getValue() + "\n"; } return ret; } + public int getStatusCode() { return status; } + public String getStatusText() { return statusText; } + public String getText() { return responseText; } -}
\ No newline at end of file +} diff --git a/gwtquery-core/src/main/java/com/google/web/bindery/requestfactory/shared/gquery/PromiseRF.java b/gwtquery-core/src/main/java/com/google/web/bindery/requestfactory/shared/gquery/PromiseRF.java index 76be5b89..9166190a 100644 --- a/gwtquery-core/src/main/java/com/google/web/bindery/requestfactory/shared/gquery/PromiseRF.java +++ b/gwtquery-core/src/main/java/com/google/web/bindery/requestfactory/shared/gquery/PromiseRF.java @@ -13,30 +13,29 @@ */ package com.google.web.bindery.requestfactory.shared.gquery; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import javax.validation.ConstraintViolation; - -import com.google.gwt.query.client.plugins.deferred.Deferred; import com.google.gwt.query.client.plugins.deferred.Deferred.DeferredPromiseImpl; import com.google.web.bindery.requestfactory.shared.Receiver; import com.google.web.bindery.requestfactory.shared.Request; import com.google.web.bindery.requestfactory.shared.RequestContext; import com.google.web.bindery.requestfactory.shared.ServerFailure; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import javax.validation.ConstraintViolation; + /** * Utility class used to create promises for RequestFactory services. * <pre> * Request<SessionProxy> req1 = loginFact.api().login(null, null); * Request<UserProxy> req2 = srvFact.api().getCurrentUser(); - * + * * // We can use `when` to append different requests * Promise requestingAll = Deferred.when(new PromiseRF(req1), new PromiseRF(req2); * // Or we can use just one promise for multiple RF requests * Promise requestingAll = new PromiseRF(req1, req2); - * + * * requestingAll.done(new Function() { * public void f() { * SessionProxy session = arguments(0, 0); @@ -47,14 +46,14 @@ import com.google.web.bindery.requestfactory.shared.ServerFailure; * public void f() { * ServerFailure failure = arguments(0); * } - * }); + * }); * </pre> */ public class PromiseRF extends DeferredPromiseImpl { private int total = 0; private List<Object> responses = new ArrayList<Object>(); private List<RequestContext> contexts = new ArrayList<RequestContext>(); - + /** * Fire a RF Request. */ @@ -70,14 +69,16 @@ public class PromiseRF extends DeferredPromiseImpl { */ public PromiseRF(Request<?>[] requests) { for (Request<?> request : requests) { - total ++; + total++; request.to(new Receiver<Object>() { public void onConstraintViolation(Set<ConstraintViolation<?>> violations) { dfd.reject(new ServerFailure("ConstraintViolation"), violations); } + public void onFailure(ServerFailure error) { dfd.reject(error); } + public void onSuccess(Object response) { responses.add(response); // Resolve only when all requests have been received diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEffectsTestGwt.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEffectsTestGwt.java index 287742fa..da19afb1 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEffectsTestGwt.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEffectsTestGwt.java @@ -66,6 +66,8 @@ public class GQueryEffectsTestGwt extends GWTTestCase { } } + // Fails in TC windows, pass in Jenkins Linux + @DoNotRunWith(Platform.HtmlUnitLayout) public void testClipAnimation() { $(e).html("<p id='idtest'>Content 1</p></p>"); @@ -116,8 +118,9 @@ public class GQueryEffectsTestGwt extends GWTTestCase { assertEquals(1, back.size()); } - // FIXME: timer 3 fails in real browsers (chrome) - @DoNotRunWith(Platform.Prod) + // Fails in TC windows, pass in Jenkins Linux + // FIXME: Also timer 3 fails in real browsers (chrome). + @DoNotRunWith(Platform.HtmlUnitLayout) public void testEffectsShouldBeQueued() { $(e).html("<p id='idtest'>Content 1</p></p>"); @@ -164,6 +167,8 @@ public class GQueryEffectsTestGwt extends GWTTestCase { timer4.schedule(duration/2); } + // Fails in TC windows, pass in Jenkins Linux + @DoNotRunWith(Platform.HtmlUnitLayout) public void testFade() { $(e) .html( @@ -354,6 +359,8 @@ public class GQueryEffectsTestGwt extends GWTTestCase { assertTrue(msg, c); } + // Fails in TC windows, pass in Jenkins Linux + @DoNotRunWith(Platform.HtmlUnitLayout) public void testAttrEffect() { $(e).html("<table border=1 id=idtest width=440><tr><td width=50%>A</td><td width=50%>B</td></tr></table>"); diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/dbinding/DataBindingTestJre.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/dbinding/DataBindingTestJre.java index 5ea76a18..50123b80 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/dbinding/DataBindingTestJre.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/dbinding/DataBindingTestJre.java @@ -16,6 +16,8 @@ package com.google.gwt.query.client.dbinding; import com.google.gwt.core.shared.GWT; +import com.google.gwt.junit.DoNotRunWith; +import com.google.gwt.junit.Platform; import com.google.gwt.junit.client.GWTTestCase; import com.google.gwt.query.client.Function; import com.google.gwt.query.client.GQ; @@ -177,8 +179,7 @@ public class DataBindingTestJre extends GWTTestCase { + " }" + "}"; - public void - test_parse_json() { + public void test_parse_json() { GUser entity = GQ.create(GUser.class); entity.parse(JSON_USER_EXAMPLE, true); @@ -191,8 +192,9 @@ public class DataBindingTestJre extends GWTTestCase { assertNotNull(entity.address().get("phone")); } - public void - test_parse_strict_json() { + // Nested strict not implemented in JS + @DoNotRunWith(Platform.Prod) + public void test_parse_strict_json() { GUser entity = GQ.create(GUser.class); entity.parse(JSON_USER_EXAMPLE, true); entity.strip(); |