From 6d304474fb84fa3f773ab1847dd9199636768c8a Mon Sep 17 00:00:00 2001 From: Hallvard Traetteberg <hal@ntnu.no> Date: Tue, 20 Aug 2019 23:02:38 +0200 Subject: [PATCH] Added google style checks and formatted all code using google style settings in Eclipse. --- simpleexample/build.gradle | 8 +- .../checkstyle/eclipse-java-google-style.xml | 337 +++++++++++++++ .../config/checkstyle/google_checks.xml | 270 ++++++++++++ .../doc/AbstractDocumentStorageImpl.java | 263 ++++++------ .../java/fxutil/doc/FileMenuController.java | 385 +++++++++--------- .../java/fxutil/doc/IDocumentImporter.java | 18 +- .../java/fxutil/doc/IDocumentListener.java | 18 +- .../main/java/fxutil/doc/IDocumentLoader.java | 21 +- .../main/java/fxutil/doc/IDocumentSaver.java | 20 +- .../java/fxutil/doc/IDocumentStorage.java | 103 ++--- .../fxutil/doc/IDocumentStorageListener.java | 18 +- .../fxutil/doc/SimpleJsonFileStorageImpl.java | 90 ++-- .../src/main/java/simpleex/core/LatLong.java | 240 +++++------ .../src/main/java/simpleex/core/LatLongs.java | 121 +++--- .../simpleex/json/LatLongDeserializer.java | 47 ++- .../java/simpleex/json/LatLongSerializer.java | 25 +- .../simpleex/json/LatLongsDeserializer.java | 33 +- .../simpleex/json/LatLongsSerializer.java | 19 +- .../simpleex/ui/DraggableNodeController.java | 171 ++++---- .../src/main/java/simpleex/ui/FxApp.java | 36 +- .../java/simpleex/ui/FxAppController.java | 291 ++++++------- .../main/java/simpleex/ui/LatLongsApp.java | 157 +++---- .../java/simpleex/ui/LatLongsStorage.java | 25 +- .../src/main/java/simpleex/ui/MapMarker.java | 20 +- .../test/java/simpleex/core/LatLongTest.java | 105 +++-- .../test/java/simpleex/core/LatLongsTest.java | 92 +++-- .../java/simpleex/json/AbstractJsonTest.java | 54 +-- .../java/simpleex/json/LatLongJsonTest.java | 53 ++- .../java/simpleex/json/LatLongsJsonTest.java | 58 +-- .../src/test/java/simpleex/ui/FxAppTest.java | 149 ++++--- 30 files changed, 1945 insertions(+), 1302 deletions(-) create mode 100644 simpleexample/config/checkstyle/eclipse-java-google-style.xml create mode 100644 simpleexample/config/checkstyle/google_checks.xml diff --git a/simpleexample/build.gradle b/simpleexample/build.gradle index 83d52c3..7ef91a7 100644 --- a/simpleexample/build.gradle +++ b/simpleexample/build.gradle @@ -10,7 +10,9 @@ plugins { // code quality with PMD id 'pmd' // code quality with SpotBugs - id "com.github.spotbugs" version "2.0.0" + id 'com.github.spotbugs' version '2.0.0' + // code quality with checkstyle + id 'checkstyle' } repositories { @@ -61,6 +63,10 @@ tasks.withType(com.github.spotbugs.SpotBugsTask) { } } +checkstyle { + configFile = project.file("config/checkstyle/google_checks.xml") +} + dependencies { compile "com.fasterxml.jackson.core:jackson-databind:2.9.8" // compile 'fischer.clemens:FxMapControl:1.0' diff --git a/simpleexample/config/checkstyle/eclipse-java-google-style.xml b/simpleexample/config/checkstyle/eclipse-java-google-style.xml new file mode 100644 index 0000000..2c502f8 --- /dev/null +++ b/simpleexample/config/checkstyle/eclipse-java-google-style.xml @@ -0,0 +1,337 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<profiles version="13"> +<profile kind="CodeFormatterProfile" name="GoogleStyle" version="13"> +<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.disabling_tag" value="@formatter:off"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation" value="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_opening_brace_in_type_declaration" 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.brace_position_for_anonymous_type_declaration" value="end_of_line"/> +<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_after_opening_brace_in_array_initializer" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_cascading_method_invocation_with_arguments.count_dependent" value="16|-1|16"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration" value="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.blank_lines_before_field" value="0"/> +<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.use_on_off_tags" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.wrap_prefer_two_fragments" value="false"/> +<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_new_line_before_else_in_if_statement" 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.keep_else_statement_on_same_line" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" 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.wrap_comment_inline_tags" value="false"/> +<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.indent_breaks_compare_to_cases" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_local_variable_declaration" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_multiple_fields" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_annotations_on_parameter" value="1040"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_annotations_on_type.count_dependent" value="1585|-1|1585"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression" value="80"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_multiple_fields.count_dependent" value="16|-1|16"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_binary_operator" 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.brace_position_for_array_initializer" value="end_of_line"/> +<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_new_line_before_finally_in_try_statement" value="do not insert"/> +<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_before_catch_in_try_statement" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_package" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression.count_dependent" value="16|4|80"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration.count_dependent" value="16|4|48"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="2"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration.count_dependent" value="16|4|49"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation" value="16"/> +<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_comma_in_superinterfaces" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_binary_operator" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_package" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_cascading_method_invocation_with_arguments" value="16"/> +<setting id="org.eclipse.jdt.core.compiler.source" value="1.7"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration.count_dependent" value="16|4|48"/> +<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_opening_paren_in_constructor_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.comment.format_line_comments" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.wrap_non_simple_local_variable_annotation" value="true"/> +<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.align_type_members_on_columns" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_member_type" value="0"/> +<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.alignment_for_enum_constants.count_dependent" value="16|5|48"/> +<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_before_opening_brace_in_method_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="16"/> +<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_unary_operator" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.comment.indent_parameter_description" value="false"/> +<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_switch" value="do not 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_angle_bracket_in_type_parameters" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="100"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation.count_dependent" value="16|4|48"/> +<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_after_opening_paren_in_parenthesized_expression" 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_opening_brace_in_constructor_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="4"/> +<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.enabling_tag" value="@formatter:on"/> +<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.alignment_for_annotations_on_package" value="1585"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_assignment" value="16"/> +<setting id="org.eclipse.jdt.core.compiler.problem.assertIdentifier" value="error"/> +<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="space"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources" 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_before_prefix_operator" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_body" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_method" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.wrap_non_simple_type_annotation" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_field_declaration" value="16"/> +<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.alignment_for_parameters_in_constructor_declaration" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_method_declaration" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try" 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_after_opening_bracket_in_array_allocation_expression" value="do not 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_comma_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_before_comma_in_method_declaration_throws" 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.brace_position_for_switch" value="end_of_line"/> +<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_before_parenthesized_expression_in_return" value="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_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_opening_paren_in_try" 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.comment.preserve_white_space_between_code_and_line_comments" value="false"/> +<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_comma_in_type_arguments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.compiler.problem.enumIdentifier" value="error"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_generic_type_arguments" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.comment_new_line_at_start_of_html_paragraph" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_ellipsis" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comment_prefix" 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.brace_position_for_method_declaration" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.compact_else_if" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.wrap_non_simple_parameter_annotation" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch" value="true"/> +<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_after_comma_in_for_increments" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_annotations_on_method" value="1585"/> +<setting id="org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column" value="true"/> +<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_new_line_after_annotation_on_field" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.comment.indent_root_tags" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_constant" value="end_of_line"/> +<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.alignment_for_union_type_in_multicatch" value="16"/> +<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_before_opening_brace_in_switch" value="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_after_comma_in_superinterfaces" 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.tabulation.size" value="2"/> +<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_new_line_after_opening_brace_in_array_initializer" value="do not 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_before_opening_bracket_in_array_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant" 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_before_opening_paren_in_constructor_declaration" 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_after_opening_paren_in_if" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation.count_dependent" value="16|5|80"/> +<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_annotations_on_parameter.count_dependent" value="1040|-1|1040"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_annotations_on_package.count_dependent" value="1585|-1|1585"/> +<setting id="org.eclipse.jdt.core.formatter.indent_empty_lines" value="false"/> +<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_closing_paren_in_cast" 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.force_if_else_statement_brace" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve" value="3"/> +<setting id="org.eclipse.jdt.core.formatter.wrap_non_simple_package_annotation" value="true"/> +<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_after_opening_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_opening_paren_in_method_invocation" 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.alignment_for_arguments_in_qualified_allocation_expression" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation.count_dependent" value="16|-1|16"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_annotations_on_type" value="1585"/> +<setting id="org.eclipse.jdt.core.compiler.compliance" value="1.7"/> +<setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer" value="2"/> +<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_before_at_in_annotation_type_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression" value="16"/> +<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_before_unary_operator" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_new_anonymous_class" value="20"/> +<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.alignment_for_annotations_on_local_variable.count_dependent" value="1585|-1|1585"/> +<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.keep_empty_array_initializer_on_one_line" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_annotations_on_field.count_dependent" value="1585|-1|1585"/> +<setting id="org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line" value="false"/> +<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_after_closing_angle_bracket_in_type_parameters" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing" 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_before_comma_in_parameterized_type_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration.count_dependent" value="16|5|80"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_binary_expression" value="16"/> +<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_new_line_after_annotation_on_type" value="insert"/> +<setting id="org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode" value="enabled"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line" value="false"/> +<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_annotation_on_parameter" 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_between_empty_parens_in_method_invocation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.comment.format_javadoc_comments" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant" value="16"/> +<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.alignment_for_arguments_in_enum_constant.count_dependent" value="16|-1|16"/> +<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="100"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_import_groups" value="0"/> +<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_semicolon" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration" value="end_of_line"/> +<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.insert_space_before_colon_in_conditional" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header" value="true"/> +<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.wrap_before_binary_operator" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations" value="2"/> +<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header" value="true"/> +<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.alignment_for_superinterfaces_in_enum_declaration" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_block" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.join_lines_in_comments" value="true"/> +<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_comma_in_multiple_field_declarations" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_compact_if" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases" value="true"/> +<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_before_colon_in_default" 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_between_empty_parens_in_constructor_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_imports" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_annotations_on_field" value="1585"/> +<setting id="org.eclipse.jdt.core.formatter.comment.format_html" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration" value="16"/> +<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_opening_bracket_in_array_allocation_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration" value="do not 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_opening_angle_bracket_in_parameterized_type_reference" 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.alignment_for_expressions_in_array_initializer.count_dependent" value="16|5|80"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.comment.format_source_code" value="true"/> +<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_after_comma_in_allocation_expression" 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.alignment_for_parameters_in_method_declaration" value="16"/> +<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.compiler.codegen.targetPlatform" value="1.7"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_resources_in_try" value="80"/> +<setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.comment.format_block_comments" value="true"/> +<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.alignment_for_enum_constants" value="0"/> +<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.indent_body_declarations_compare_to_annotation_declaration_header" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block" value="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_closing_paren_in_catch" 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.alignment_for_superinterfaces_in_type_declaration.count_dependent" value="16|4|48"/> +<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_comma_in_for_increments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_annotations_on_method.count_dependent" value="1585|-1|1585"/> +<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_before_colon_in_assert" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_type_declaration" value="end_of_line"/> +<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_between_empty_braces_in_array_initializer" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_binary_expression.count_dependent" value="16|-1|16"/> +<setting id="org.eclipse.jdt.core.formatter.wrap_non_simple_member_annotation" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_annotations_on_local_variable" value="1585"/> +<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_before_semicolon_in_for" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call.count_dependent" value="16|5|80"/> +<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_angle_bracket_in_parameterized_type_reference" value="do not 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_before_closing_paren_in_annotation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_generic_type_arguments.count_dependent" value="16|-1|16"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression.count_dependent" value="16|5|80"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration.count_dependent" value="16|5|80"/> +<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_imports" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_for_statement" value="16"/> +<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.never_indent_block_comments_on_first_column" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line" value="false"/> +</profile> +</profiles> \ No newline at end of file diff --git a/simpleexample/config/checkstyle/google_checks.xml b/simpleexample/config/checkstyle/google_checks.xml new file mode 100644 index 0000000..ef32ef1 --- /dev/null +++ b/simpleexample/config/checkstyle/google_checks.xml @@ -0,0 +1,270 @@ +<?xml version="1.0"?> +<!DOCTYPE module PUBLIC + "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" + "https://checkstyle.org/dtds/configuration_1_3.dtd"> + +<!-- + Checkstyle configuration that checks the Google coding conventions from Google Java Style + that can be found at https://google.github.io/styleguide/javaguide.html + + Checkstyle is very configurable. Be sure to read the documentation at + http://checkstyle.sf.net (or in your downloaded distribution). + + To completely disable a check, just comment it out or delete it from the file. + + Authors: Max Vetrenko, Ruslan Diachenko, Roman Ivanov. + --> + +<module name = "Checker"> + <property name="charset" value="UTF-8"/> + + <property name="severity" value="warning"/> + + <property name="fileExtensions" value="java, properties, xml"/> + <!-- Excludes all 'module-info.java' files --> + <!-- See https://checkstyle.org/config_filefilters.html --> + <module name="BeforeExecutionExclusionFileFilter"> + <property name="fileNamePattern" value="module\-info\.java$"/> + </module> + <!-- Checks for whitespace --> + <!-- See http://checkstyle.sf.net/config_whitespace.html --> + <module name="FileTabCharacter"> + <property name="eachLine" value="true"/> + </module> + + <module name="TreeWalker"> + <module name="OuterTypeFilename"/> + <module name="IllegalTokenText"> + <property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/> + <property name="format" + value="\\u00(09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/> + <property name="message" + value="Consider using special escape sequence instead of octal value or Unicode escaped value."/> + </module> + <module name="AvoidEscapedUnicodeCharacters"> + <property name="allowEscapesForControlCharacters" value="true"/> + <property name="allowByTailComment" value="true"/> + <property name="allowNonPrintableEscapes" value="true"/> + </module> + <module name="LineLength"> + <property name="max" value="100"/> + <property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/> + </module> + <module name="AvoidStarImport"/> + <module name="OneTopLevelClass"/> + <module name="NoLineWrap"/> + <module name="EmptyBlock"> + <property name="option" value="TEXT"/> + <property name="tokens" + value="LITERAL_TRY, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH"/> + </module> + <module name="NeedBraces"/> + <module name="LeftCurly"/> + <module name="RightCurly"> + <property name="id" value="RightCurlySame"/> + <property name="tokens" + value="LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, + LITERAL_DO"/> + </module> + <module name="RightCurly"> + <property name="id" value="RightCurlyAlone"/> + <property name="option" value="alone"/> + <property name="tokens" + value="CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, STATIC_INIT, + INSTANCE_INIT"/> + </module> + <module name="WhitespaceAround"> + <property name="allowEmptyConstructors" value="true"/> + <property name="allowEmptyLambdas" value="true"/> + <property name="allowEmptyMethods" value="true"/> + <property name="allowEmptyTypes" value="true"/> + <property name="allowEmptyLoops" value="true"/> + <message key="ws.notFollowed" + value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks may only be represented as '{}' when not part of a multi-block statement (4.1.3)"/> + <message key="ws.notPreceded" + value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/> + </module> + <module name="OneStatementPerLine"/> + <module name="MultipleVariableDeclarations"/> + <module name="ArrayTypeStyle"/> + <module name="MissingSwitchDefault"/> + <module name="FallThrough"/> + <module name="UpperEll"/> + <module name="ModifierOrder"/> + <module name="EmptyLineSeparator"> + <property name="allowNoEmptyLineBetweenFields" value="true"/> + </module> + <module name="SeparatorWrap"> + <property name="id" value="SeparatorWrapDot"/> + <property name="tokens" value="DOT"/> + <property name="option" value="nl"/> + </module> + <module name="SeparatorWrap"> + <property name="id" value="SeparatorWrapComma"/> + <property name="tokens" value="COMMA"/> + <property name="option" value="EOL"/> + </module> + <module name="SeparatorWrap"> + <!-- ELLIPSIS is EOL until https://github.com/google/styleguide/issues/258 --> + <property name="id" value="SeparatorWrapEllipsis"/> + <property name="tokens" value="ELLIPSIS"/> + <property name="option" value="EOL"/> + </module> + <module name="SeparatorWrap"> + <!-- ARRAY_DECLARATOR is EOL until https://github.com/google/styleguide/issues/259 --> + <property name="id" value="SeparatorWrapArrayDeclarator"/> + <property name="tokens" value="ARRAY_DECLARATOR"/> + <property name="option" value="EOL"/> + </module> + <module name="SeparatorWrap"> + <property name="id" value="SeparatorWrapMethodRef"/> + <property name="tokens" value="METHOD_REF"/> + <property name="option" value="nl"/> + </module> + <module name="PackageName"> + <property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/> + <message key="name.invalidPattern" + value="Package name ''{0}'' must match pattern ''{1}''."/> + </module> + <module name="TypeName"> + <message key="name.invalidPattern" + value="Type name ''{0}'' must match pattern ''{1}''."/> + </module> + <module name="MemberName"> + <property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/> + <message key="name.invalidPattern" + value="Member name ''{0}'' must match pattern ''{1}''."/> + </module> + <module name="ParameterName"> + <property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/> + <message key="name.invalidPattern" + value="Parameter name ''{0}'' must match pattern ''{1}''."/> + </module> + <module name="LambdaParameterName"> + <property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/> + <message key="name.invalidPattern" + value="Lambda parameter name ''{0}'' must match pattern ''{1}''."/> + </module> + <module name="CatchParameterName"> + <property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/> + <message key="name.invalidPattern" + value="Catch parameter name ''{0}'' must match pattern ''{1}''."/> + </module> + <module name="LocalVariableName"> + <property name="tokens" value="VARIABLE_DEF"/> + <property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/> + <message key="name.invalidPattern" + value="Local variable name ''{0}'' must match pattern ''{1}''."/> + </module> + <module name="ClassTypeParameterName"> + <property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/> + <message key="name.invalidPattern" + value="Class type name ''{0}'' must match pattern ''{1}''."/> + </module> + <module name="MethodTypeParameterName"> + <property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/> + <message key="name.invalidPattern" + value="Method type name ''{0}'' must match pattern ''{1}''."/> + </module> + <module name="InterfaceTypeParameterName"> + <property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/> + <message key="name.invalidPattern" + value="Interface type name ''{0}'' must match pattern ''{1}''."/> + </module> + <module name="NoFinalizer"/> + <module name="GenericWhitespace"> + <message key="ws.followed" + value="GenericWhitespace ''{0}'' is followed by whitespace."/> + <message key="ws.preceded" + value="GenericWhitespace ''{0}'' is preceded with whitespace."/> + <message key="ws.illegalFollow" + value="GenericWhitespace ''{0}'' should followed by whitespace."/> + <message key="ws.notPreceded" + value="GenericWhitespace ''{0}'' is not preceded with whitespace."/> + </module> + <module name="Indentation"> + <property name="basicOffset" value="2"/> + <property name="braceAdjustment" value="0"/> + <property name="caseIndent" value="2"/> + <property name="throwsIndent" value="4"/> + <property name="lineWrappingIndentation" value="4"/> + <property name="arrayInitIndent" value="2"/> + </module> + <module name="AbbreviationAsWordInName"> + <property name="ignoreFinal" value="false"/> + <property name="allowedAbbreviationLength" value="1"/> + </module> + <module name="OverloadMethodsDeclarationOrder"/> + <module name="VariableDeclarationUsageDistance"/> + <module name="CustomImportOrder"> + <property name="sortImportsInGroupAlphabetically" value="true"/> + <property name="separateLineBetweenGroups" value="true"/> + <property name="customImportOrderRules" value="STATIC###THIRD_PARTY_PACKAGE"/> + </module> + <module name="MethodParamPad"/> + <module name="NoWhitespaceBefore"> + <property name="tokens" + value="COMMA, SEMI, POST_INC, POST_DEC, DOT, ELLIPSIS, METHOD_REF"/> + <property name="allowLineBreaks" value="true"/> + </module> + <module name="ParenPad"/> + <module name="OperatorWrap"> + <property name="option" value="NL"/> + <property name="tokens" + value="BAND, BOR, BSR, BXOR, DIV, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR, + LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR, METHOD_REF "/> + </module> + <module name="AnnotationLocation"> + <property name="id" value="AnnotationLocationMostCases"/> + <property name="tokens" + value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF"/> + </module> + <module name="AnnotationLocation"> + <property name="id" value="AnnotationLocationVariables"/> + <property name="tokens" value="VARIABLE_DEF"/> + <property name="allowSamelineMultipleAnnotations" value="true"/> + </module> + <module name="NonEmptyAtclauseDescription"/> + <!-- Removed due to instantiation exception + <module name="InvalidJavadocPosition"/> + --> + <module name="JavadocTagContinuationIndentation"/> + <module name="SummaryJavadoc"> + <property name="forbiddenSummaryFragments" + value="^@return the *|^This method returns |^A [{]@code [a-zA-Z0-9]+[}]( is a )"/> + </module> + <module name="JavadocParagraph"/> + <module name="AtclauseOrder"> + <property name="tagOrder" value="@param, @return, @throws, @deprecated"/> + <property name="target" + value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/> + </module> + <module name="JavadocMethod"> + <property name="scope" value="public"/> + <property name="allowMissingParamTags" value="true"/> + <property name="allowMissingThrowsTags" value="true"/> + <property name="allowMissingReturnTag" value="true"/> + <property name="allowedAnnotations" value="Override, Test"/> + <property name="allowThrowsTagsForSubclasses" value="true"/> + </module> + <!-- Removed due to instantiation exception + <module name="MissingJavadocMethod"> + <property name="scope" value="public"/> + <property name="minLineCount" value="2"/> + <property name="allowedAnnotations" value="Override, Test"/> + </module> + --> + <module name="MethodName"> + <property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/> + <message key="name.invalidPattern" + value="Method name ''{0}'' must match pattern ''{1}''."/> + </module> + <module name="SingleLineJavadoc"> + <property name="ignoreInlineTags" value="false"/> + </module> + <module name="EmptyCatchBlock"> + <property name="exceptionVariableName" value="expected"/> + </module> + <module name="CommentsIndentation"/> + </module> +</module> diff --git a/simpleexample/src/main/java/fxutil/doc/AbstractDocumentStorageImpl.java b/simpleexample/src/main/java/fxutil/doc/AbstractDocumentStorageImpl.java index d602b6c..95def60 100644 --- a/simpleexample/src/main/java/fxutil/doc/AbstractDocumentStorageImpl.java +++ b/simpleexample/src/main/java/fxutil/doc/AbstractDocumentStorageImpl.java @@ -10,136 +10,145 @@ import java.util.ArrayList; import java.util.Collection; /** - * Incomplete implementation of **IDocumentStorage**, to simplify implementing ones for specific document and location types. - * The main missing methods are for getting and setting the current document, creating an empty one and - * creating an **InputStream** from a location. + * Incomplete implementation of **IDocumentStorage**, to simplify implementing ones for specific + * document and location types. The main missing methods are for getting and setting the current + * document, creating an empty one and creating an **InputStream** from a location. + * * @author hal * * @param <D> the document type * @param <L> the location type */ -public abstract class AbstractDocumentStorageImpl<D, L> implements IDocumentStorage<L>, IDocumentPersistence<D, L> { - - private L documentLocation = null; - - @Override - public L getDocumentLocation() { - return documentLocation; - } - - @Override - public void setDocumentLocation(final L documentLocation) { - final L oldDocumentLocation = this.documentLocation; - this.documentLocation = documentLocation; - fireDocumentLocationChanged(oldDocumentLocation); - } - - protected void setDocumentAndLocation(final D document, final L documentLocation) { - setDocument(document); - setDocumentLocation(documentLocation); - } - - /** - * Returns the current document. - * @return the current document - */ - protected abstract D getDocument(); - - /** - * Sets the current document - * @param document the new document - */ - protected abstract void setDocument(D document); - - // - - private final Collection<IDocumentStorageListener<L>> documentListeners = new ArrayList<IDocumentStorageListener<L>>(); - - @Override - public void addDocumentStorageListener(final IDocumentStorageListener<L> documentStorageListener) { - documentListeners.add(documentStorageListener); - } - - @Override - public void removeDocumentStorageListener(final IDocumentStorageListener<L> documentStorageListener) { - documentListeners.remove(documentStorageListener); - } - - protected void fireDocumentLocationChanged(final L oldDocumentLocation) { - for (final IDocumentStorageListener<L> documentStorageListener : documentListeners) { - documentStorageListener.documentLocationChanged(documentLocation, oldDocumentLocation); - } - } - - protected void fireDocumentChanged(final D oldDocument) { - for (final IDocumentStorageListener<L> documentListener : documentListeners) { - if (documentListener instanceof IDocumentListener) { - ((IDocumentListener<D, L>) documentListener).documentChanged(getDocument(), oldDocument); - } - } - } - - /** - * Creates a new and empty document. - * @return - */ - protected abstract D createDocument(); - - @Override - public void newDocument() { - setDocumentAndLocation(createDocument(), null); - } - - /** - * Creates an ImportStream from a location - * @param location - * @return - * @throws IOException - */ - protected abstract InputStream toInputStream(L location) throws IOException; - - protected InputStream toInputStream(final File location) throws IOException { - return new FileInputStream(location); - } - - protected InputStream toInputStream(final URL location) throws IOException { - return location.openStream(); - } - - protected InputStream toInputStream(final URI location) throws IOException { - return toInputStream(location.toURL()); - } - - @Override - public void openDocument(final L storage) throws IOException { - try (InputStream input = toInputStream(storage)){ - setDocumentAndLocation(loadDocument(input), storage); - } catch (final Exception e) { - throw new IOException(e); - } - } - - @Override - public void saveDocument() throws IOException { - try { - saveDocument(getDocument(), getDocumentLocation()); - } catch (final Exception e) { - throw new IOException(e); - } - } - - public void saveDocumentAs(final L documentLocation) throws IOException { - final L oldDocumentLocation = getDocumentLocation(); - setDocumentLocation(documentLocation); - try { - saveDocument(); - } catch (final IOException e) { - setDocumentLocation(oldDocumentLocation); - throw e; - } - } - - public void saveCopyAs(final L documentLocation) throws Exception { - saveDocument(getDocument(), documentLocation); - } +public abstract class AbstractDocumentStorageImpl<D, L> + implements IDocumentStorage<L>, IDocumentPersistence<D, L> { + + private L documentLocation = null; + + @Override + public L getDocumentLocation() { + return documentLocation; + } + + @Override + public void setDocumentLocation(final L documentLocation) { + final L oldDocumentLocation = this.documentLocation; + this.documentLocation = documentLocation; + fireDocumentLocationChanged(oldDocumentLocation); + } + + protected void setDocumentAndLocation(final D document, final L documentLocation) { + setDocument(document); + setDocumentLocation(documentLocation); + } + + /** + * Returns the current document. + * + * @return the current document + */ + protected abstract D getDocument(); + + /** + * Sets the current document + * + * @param document the new document + */ + protected abstract void setDocument(D document); + + // + + private final Collection<IDocumentStorageListener<L>> documentListeners = + new ArrayList<IDocumentStorageListener<L>>(); + + @Override + public void addDocumentStorageListener( + final IDocumentStorageListener<L> documentStorageListener) { + documentListeners.add(documentStorageListener); + } + + @Override + public void removeDocumentStorageListener( + final IDocumentStorageListener<L> documentStorageListener) { + documentListeners.remove(documentStorageListener); + } + + protected void fireDocumentLocationChanged(final L oldDocumentLocation) { + for (final IDocumentStorageListener<L> documentStorageListener : documentListeners) { + documentStorageListener.documentLocationChanged(documentLocation, oldDocumentLocation); + } + } + + protected void fireDocumentChanged(final D oldDocument) { + for (final IDocumentStorageListener<L> documentListener : documentListeners) { + if (documentListener instanceof IDocumentListener) { + ((IDocumentListener<D, L>) documentListener).documentChanged(getDocument(), oldDocument); + } + } + } + + /** + * Creates a new and empty document. + * + * @return + */ + protected abstract D createDocument(); + + @Override + public void newDocument() { + setDocumentAndLocation(createDocument(), null); + } + + /** + * Creates an ImportStream from a location + * + * @param location + * @return + * @throws IOException + */ + protected abstract InputStream toInputStream(L location) throws IOException; + + protected InputStream toInputStream(final File location) throws IOException { + return new FileInputStream(location); + } + + protected InputStream toInputStream(final URL location) throws IOException { + return location.openStream(); + } + + protected InputStream toInputStream(final URI location) throws IOException { + return toInputStream(location.toURL()); + } + + @Override + public void openDocument(final L storage) throws IOException { + try (InputStream input = toInputStream(storage)) { + setDocumentAndLocation(loadDocument(input), storage); + } catch (final Exception e) { + throw new IOException(e); + } + } + + @Override + public void saveDocument() throws IOException { + try { + saveDocument(getDocument(), getDocumentLocation()); + } catch (final Exception e) { + throw new IOException(e); + } + } + + public void saveDocumentAs(final L documentLocation) throws IOException { + final L oldDocumentLocation = getDocumentLocation(); + setDocumentLocation(documentLocation); + try { + saveDocument(); + } catch (final IOException e) { + setDocumentLocation(oldDocumentLocation); + throw e; + } + } + + public void saveCopyAs(final L documentLocation) throws Exception { + saveDocument(getDocument(), documentLocation); + } } diff --git a/simpleexample/src/main/java/fxutil/doc/FileMenuController.java b/simpleexample/src/main/java/fxutil/doc/FileMenuController.java index 406a211..692db2b 100644 --- a/simpleexample/src/main/java/fxutil/doc/FileMenuController.java +++ b/simpleexample/src/main/java/fxutil/doc/FileMenuController.java @@ -9,7 +9,6 @@ import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.Optional; - import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.Alert; @@ -22,196 +21,196 @@ import javafx.stage.FileChooser; public class FileMenuController { - private IDocumentStorage<File> documentStorage; - - public void setDocumentStorage(final IDocumentStorage<File> documentStorage) { - this.documentStorage = documentStorage; - if (importMenu != null) { - importMenu.setDisable(documentStorage.getDocumentImporters().isEmpty()); - } - } - - @FXML - public void handleNewAction() { - documentStorage.newDocument(); - } - - private final List<File> recentFiles = new ArrayList<File>(); - - @FXML - private Menu recentMenu; - - protected void updateRecentMenu(final File file) { - recentFiles.remove(file); - recentFiles.add(0, file); - recentMenu.getItems().clear(); - for (final File recentFile : recentFiles) { - final MenuItem menuItem = new MenuItem(); - menuItem.setText(recentFile.toString()); - menuItem.setOnAction(event -> handleOpenAction(event)); - recentMenu.getItems().add(menuItem); - } - } - - private FileChooser fileChooser; - - FileChooser getFileChooser() { - if (fileChooser == null) { - fileChooser = new FileChooser(); - } - return fileChooser; - } - - @FXML - public void handleOpenAction(final ActionEvent event) { - File selection = null; - if (event.getSource() instanceof MenuItem) { - final File file = new File(((MenuItem) event.getSource()).getText()); - if (file.exists()) { - selection = file; - } - } - if (selection == null) { - final FileChooser fileChooser = getFileChooser(); - selection = fileChooser.showOpenDialog(null); - } - if (selection != null) { - handleOpenAction(selection); - } - } - - private void showExceptionDialog(final String message) { - final Alert alert = new Alert(AlertType.ERROR, message, ButtonType.CLOSE); - alert.showAndWait(); - } - - private void showExceptionDialog(final String message, final Exception e) { - showExceptionDialog(message + ": " + e.getLocalizedMessage()); - } - - void handleOpenAction(final File selection) { - try { - documentStorage.openDocument(selection); - updateRecentMenu(selection); - } catch (final IOException e) { - showExceptionDialog("Oops, problem when opening " + selection, e); - } - } - - private void showSaveExceptionDialog(final File location, final Exception e) { - showExceptionDialog("Oops, problem saving to " + location, e); - } - - @FXML - public void handleSaveAction() { - if (documentStorage.getDocumentLocation() == null) { - handleSaveAsAction(); - } else { - try { - documentStorage.saveDocument(); - } catch (final IOException e) { - showSaveExceptionDialog(documentStorage.getDocumentLocation(), e); - } - } - } - - @FXML - public void handleSaveAsAction() { - final FileChooser fileChooser = getFileChooser(); - final File selection = fileChooser.showSaveDialog(null); - handleSaveAsAction(selection); - } - - void handleSaveAsAction(final File selection) { - final File oldStorage = documentStorage.getDocumentLocation(); - try { - documentStorage.setDocumentLocation(selection); - documentStorage.saveDocument(); - } catch (final IOException e) { - showSaveExceptionDialog(documentStorage.getDocumentLocation(), e); - documentStorage.setDocumentLocation(oldStorage); - } - } - - @FXML - public void handleSaveCopyAsAction() { - final FileChooser fileChooser = getFileChooser(); - final File selection = fileChooser.showSaveDialog(null); - handleSaveCopyAsAction(selection); - } - - void handleSaveCopyAsAction(final File selection) { - final File oldStorage = documentStorage.getDocumentLocation(); - try { - documentStorage.setDocumentLocation(selection); - documentStorage.saveDocument(); - } catch (final IOException e) { - showSaveExceptionDialog(selection, e); - } finally { - documentStorage.setDocumentLocation(oldStorage); - } - } - - @FXML - private Menu importMenu; - - @FXML - public void handleFileImportAction() { - final FileChooser fileChooser = getFileChooser(); - final File selection = fileChooser.showOpenDialog(null); - // String path = selection.getPath(); - // int pos = path.lastIndexOf('.'); - // String ext = (pos > 0 ? path.substring(pos + 1) : null); - handleFileImportAction(selection); - } - - void handleFileImportAction(final File selection) { - for (final IDocumentImporter importer : documentStorage.getDocumentImporters()) { - try (InputStream input = new FileInputStream(selection)) { - importer.importDocument(input); - break; - } catch (final Exception e) { - } - } - } - - private TextInputDialog inputDialog; - - @FXML - public void handleURLImportAction() { - if (inputDialog == null) { - inputDialog = new TextInputDialog(); - } - inputDialog.setTitle("Import from URL"); - inputDialog.setHeaderText("Enter URL to import from"); - inputDialog.setContentText("Enter URL: "); - // https://developer.garmin.com/downloads/connect-api/sample_file.gpx - while (true) { - final Optional<String> result = inputDialog.showAndWait(); - if (! result.isPresent()) { - break; - } - try { - if (handleURLImportAction(new URL(result.get()))) { - break; - } - inputDialog.setHeaderText("Problems reading it..."); - inputDialog.setContentText("Enter another URL: "); - } catch (final MalformedURLException e1) { - inputDialog.setContentText("Enter a valid URL: "); - } - } - } - - boolean handleURLImportAction(final URL url) { - for (final IDocumentImporter importer : documentStorage.getDocumentImporters()) { - try (InputStream input = url.openStream()) { - importer.importDocument(input); - return true; - } catch (final Exception e) { - System.err.println(e.getMessage()); - } - } - return false; - } + private IDocumentStorage<File> documentStorage; + + public void setDocumentStorage(final IDocumentStorage<File> documentStorage) { + this.documentStorage = documentStorage; + if (importMenu != null) { + importMenu.setDisable(documentStorage.getDocumentImporters().isEmpty()); + } + } + + @FXML + public void handleNewAction() { + documentStorage.newDocument(); + } + + private final List<File> recentFiles = new ArrayList<File>(); + + @FXML + private Menu recentMenu; + + protected void updateRecentMenu(final File file) { + recentFiles.remove(file); + recentFiles.add(0, file); + recentMenu.getItems().clear(); + for (final File recentFile : recentFiles) { + final MenuItem menuItem = new MenuItem(); + menuItem.setText(recentFile.toString()); + menuItem.setOnAction(event -> handleOpenAction(event)); + recentMenu.getItems().add(menuItem); + } + } + + private FileChooser fileChooser; + + FileChooser getFileChooser() { + if (fileChooser == null) { + fileChooser = new FileChooser(); + } + return fileChooser; + } + + @FXML + public void handleOpenAction(final ActionEvent event) { + File selection = null; + if (event.getSource() instanceof MenuItem) { + final File file = new File(((MenuItem) event.getSource()).getText()); + if (file.exists()) { + selection = file; + } + } + if (selection == null) { + final FileChooser fileChooser = getFileChooser(); + selection = fileChooser.showOpenDialog(null); + } + if (selection != null) { + handleOpenAction(selection); + } + } + + private void showExceptionDialog(final String message) { + final Alert alert = new Alert(AlertType.ERROR, message, ButtonType.CLOSE); + alert.showAndWait(); + } + + private void showExceptionDialog(final String message, final Exception e) { + showExceptionDialog(message + ": " + e.getLocalizedMessage()); + } + + void handleOpenAction(final File selection) { + try { + documentStorage.openDocument(selection); + updateRecentMenu(selection); + } catch (final IOException e) { + showExceptionDialog("Oops, problem when opening " + selection, e); + } + } + + private void showSaveExceptionDialog(final File location, final Exception e) { + showExceptionDialog("Oops, problem saving to " + location, e); + } + + @FXML + public void handleSaveAction() { + if (documentStorage.getDocumentLocation() == null) { + handleSaveAsAction(); + } else { + try { + documentStorage.saveDocument(); + } catch (final IOException e) { + showSaveExceptionDialog(documentStorage.getDocumentLocation(), e); + } + } + } + + @FXML + public void handleSaveAsAction() { + final FileChooser fileChooser = getFileChooser(); + final File selection = fileChooser.showSaveDialog(null); + handleSaveAsAction(selection); + } + + void handleSaveAsAction(final File selection) { + final File oldStorage = documentStorage.getDocumentLocation(); + try { + documentStorage.setDocumentLocation(selection); + documentStorage.saveDocument(); + } catch (final IOException e) { + showSaveExceptionDialog(documentStorage.getDocumentLocation(), e); + documentStorage.setDocumentLocation(oldStorage); + } + } + + @FXML + public void handleSaveCopyAsAction() { + final FileChooser fileChooser = getFileChooser(); + final File selection = fileChooser.showSaveDialog(null); + handleSaveCopyAsAction(selection); + } + + void handleSaveCopyAsAction(final File selection) { + final File oldStorage = documentStorage.getDocumentLocation(); + try { + documentStorage.setDocumentLocation(selection); + documentStorage.saveDocument(); + } catch (final IOException e) { + showSaveExceptionDialog(selection, e); + } finally { + documentStorage.setDocumentLocation(oldStorage); + } + } + + @FXML + private Menu importMenu; + + @FXML + public void handleFileImportAction() { + final FileChooser fileChooser = getFileChooser(); + final File selection = fileChooser.showOpenDialog(null); + // String path = selection.getPath(); + // int pos = path.lastIndexOf('.'); + // String ext = (pos > 0 ? path.substring(pos + 1) : null); + handleFileImportAction(selection); + } + + void handleFileImportAction(final File selection) { + for (final IDocumentImporter importer : documentStorage.getDocumentImporters()) { + try (InputStream input = new FileInputStream(selection)) { + importer.importDocument(input); + break; + } catch (final Exception e) { + } + } + } + + private TextInputDialog inputDialog; + + @FXML + public void handleURLImportAction() { + if (inputDialog == null) { + inputDialog = new TextInputDialog(); + } + inputDialog.setTitle("Import from URL"); + inputDialog.setHeaderText("Enter URL to import from"); + inputDialog.setContentText("Enter URL: "); + // https://developer.garmin.com/downloads/connect-api/sample_file.gpx + while (true) { + final Optional<String> result = inputDialog.showAndWait(); + if (!result.isPresent()) { + break; + } + try { + if (handleURLImportAction(new URL(result.get()))) { + break; + } + inputDialog.setHeaderText("Problems reading it..."); + inputDialog.setContentText("Enter another URL: "); + } catch (final MalformedURLException e1) { + inputDialog.setContentText("Enter a valid URL: "); + } + } + } + + boolean handleURLImportAction(final URL url) { + for (final IDocumentImporter importer : documentStorage.getDocumentImporters()) { + try (InputStream input = url.openStream()) { + importer.importDocument(input); + return true; + } catch (final Exception e) { + System.err.println(e.getMessage()); + } + } + return false; + } } diff --git a/simpleexample/src/main/java/fxutil/doc/IDocumentImporter.java b/simpleexample/src/main/java/fxutil/doc/IDocumentImporter.java index be436c3..9c7a839 100644 --- a/simpleexample/src/main/java/fxutil/doc/IDocumentImporter.java +++ b/simpleexample/src/main/java/fxutil/doc/IDocumentImporter.java @@ -4,16 +4,18 @@ import java.io.IOException; import java.io.InputStream; /** - * An interface with a method for importing domain data from a location. - * The main use is supporting an **import** action in a **File** menu. + * An interface with a method for importing domain data from a location. The main use is supporting + * an **import** action in a **File** menu. + * * @author hal * */ public interface IDocumentImporter { - /** - * Loads a document from the input stream and sets it as the current document. - * @param inputStream - * @throws IOException - */ - public void importDocument(InputStream inputStream) throws IOException; + /** + * Loads a document from the input stream and sets it as the current document. + * + * @param inputStream + * @throws IOException + */ + public void importDocument(InputStream inputStream) throws IOException; } diff --git a/simpleexample/src/main/java/fxutil/doc/IDocumentListener.java b/simpleexample/src/main/java/fxutil/doc/IDocumentListener.java index ec63781..c8c3079 100644 --- a/simpleexample/src/main/java/fxutil/doc/IDocumentListener.java +++ b/simpleexample/src/main/java/fxutil/doc/IDocumentListener.java @@ -1,18 +1,20 @@ package fxutil.doc; /** - * Listener interface for the (contents of) the (current) document of an IDocumentStorage, e.g. - * when an **open** action is performed. + * Listener interface for the (contents of) the (current) document of an IDocumentStorage, e.g. when + * an **open** action is performed. + * * @author hal * * @param <D> the document type * @param <L> the location type */ public interface IDocumentListener<D, L> extends IDocumentStorageListener<L> { - /** - * Notifies that the current document has changed. - * @param document the new document - * @param oldDocument the previous document - */ - public void documentChanged(D document, D oldDocument); + /** + * Notifies that the current document has changed. + * + * @param document the new document + * @param oldDocument the previous document + */ + public void documentChanged(D document, D oldDocument); } diff --git a/simpleexample/src/main/java/fxutil/doc/IDocumentLoader.java b/simpleexample/src/main/java/fxutil/doc/IDocumentLoader.java index 69fef49..5078db2 100644 --- a/simpleexample/src/main/java/fxutil/doc/IDocumentLoader.java +++ b/simpleexample/src/main/java/fxutil/doc/IDocumentLoader.java @@ -3,18 +3,21 @@ package fxutil.doc; import java.io.InputStream; /** - * An interface with a method for loading and returning a document (domain data container) from an InputStream. - * This allows various ways of loading or importing domain data, with different sources and formats. + * An interface with a method for loading and returning a document (domain data container) from an + * InputStream. This allows various ways of loading or importing domain data, with different sources + * and formats. + * * @author hal * * @param <D> the document type */ public interface IDocumentLoader<D> { - /** - * Loads and returns a new document from an InputStream - * @param inputStream - * @return - * @throws Exception - */ - public D loadDocument(InputStream inputStream) throws Exception; + /** + * Loads and returns a new document from an InputStream + * + * @param inputStream + * @return + * @throws Exception + */ + public D loadDocument(InputStream inputStream) throws Exception; } diff --git a/simpleexample/src/main/java/fxutil/doc/IDocumentSaver.java b/simpleexample/src/main/java/fxutil/doc/IDocumentSaver.java index 6754304..2bca45c 100644 --- a/simpleexample/src/main/java/fxutil/doc/IDocumentSaver.java +++ b/simpleexample/src/main/java/fxutil/doc/IDocumentSaver.java @@ -1,19 +1,21 @@ package fxutil.doc; /** - * An interface with a method for saving a document (domain data container) to a location. - * This allows various ways of saving or exporting domain data, to different locations and formats. + * An interface with a method for saving a document (domain data container) to a location. This + * allows various ways of saving or exporting domain data, to different locations and formats. + * * @author hal * * @param <D> the document type * @param <L> the location type */ public interface IDocumentSaver<D, L> { - /** - * Saves the provided document to the provided location - * @param document - * @param documentLocation - * @throws Exception - */ - public void saveDocument(D document, L documentLocation) throws Exception; + /** + * Saves the provided document to the provided location + * + * @param document + * @param documentLocation + * @throws Exception + */ + public void saveDocument(D document, L documentLocation) throws Exception; } diff --git a/simpleexample/src/main/java/fxutil/doc/IDocumentStorage.java b/simpleexample/src/main/java/fxutil/doc/IDocumentStorage.java index 698c158..3317705 100644 --- a/simpleexample/src/main/java/fxutil/doc/IDocumentStorage.java +++ b/simpleexample/src/main/java/fxutil/doc/IDocumentStorage.java @@ -4,56 +4,65 @@ import java.io.IOException; import java.util.Collection; /** - * An interface with the methods necessary for supporting the standard File menu actions. - * The class representing the document (domain data container) is implicit in the implementation of this interface. - * The interface includes methods for getting and setting the location and creating, opening and saving the (current) document. + * An interface with the methods necessary for supporting the standard File menu actions. The class + * representing the document (domain data container) is implicit in the implementation of this + * interface. The interface includes methods for getting and setting the location and creating, + * opening and saving the (current) document. + * * @author hal * * @param <L> The type of the location, typically java.io.File. */ public interface IDocumentStorage<L> { - /** - * Returns the current location (of the current document). - * @return the current location - */ - public L getDocumentLocation(); - - /** - * Sets the current location (of the current document), can be used by a save-as action. - * @param documentLocation - */ - public void setDocumentLocation(L documentLocation); - - /** - * Adds an IDocumentStorageListener that will be notified when the current location changes. - * @param documentStorageListener - */ - - public void addDocumentStorageListener(IDocumentStorageListener<L> documentStorageListener); - /** - * Removes an IDocumentStorageListener. - * @param documentStorageListener - */ - public void removeDocumentStorageListener(IDocumentStorageListener<L> documentStorageListener); - - /** - * Creates a new documents and sets it as the current one, can be used by a new action. - */ - public void newDocument(); - - /** - * Loads a documents from the provided location and sets it as the current one, can be used by an open action. - */ - public void openDocument(L documentLocation) throws IOException; - - /** - * Saves the current document (to the current location), can be used by a save action. - */ - public void saveDocument() throws IOException; - - /** - * Returns the set of IDocumentImporters, can be used by an import action. - * @return - */ - public Collection<IDocumentImporter> getDocumentImporters(); + /** + * Returns the current location (of the current document). + * + * @return the current location + */ + public L getDocumentLocation(); + + /** + * Sets the current location (of the current document), can be used by a save-as action. + * + * @param documentLocation + */ + public void setDocumentLocation(L documentLocation); + + /** + * Adds an IDocumentStorageListener that will be notified when the current location changes. + * + * @param documentStorageListener + */ + + public void addDocumentStorageListener(IDocumentStorageListener<L> documentStorageListener); + + /** + * Removes an IDocumentStorageListener. + * + * @param documentStorageListener + */ + public void removeDocumentStorageListener(IDocumentStorageListener<L> documentStorageListener); + + /** + * Creates a new documents and sets it as the current one, can be used by a new action. + */ + public void newDocument(); + + /** + * Loads a documents from the provided location and sets it as the current one, can be used by an + * open action. + */ + public void openDocument(L documentLocation) throws IOException; + + /** + * Saves the current document (to the current location), can be used by a save action. + */ + public void saveDocument() throws IOException; + + /** + * Returns the set of IDocumentImporters, can be used by an import action. + * + * @return + */ + public Collection<IDocumentImporter> getDocumentImporters(); } diff --git a/simpleexample/src/main/java/fxutil/doc/IDocumentStorageListener.java b/simpleexample/src/main/java/fxutil/doc/IDocumentStorageListener.java index d781f1c..15d0e6e 100644 --- a/simpleexample/src/main/java/fxutil/doc/IDocumentStorageListener.java +++ b/simpleexample/src/main/java/fxutil/doc/IDocumentStorageListener.java @@ -1,17 +1,19 @@ package fxutil.doc; /** - * Listener interface for the (current) location of the (current) document of an IDocumentStorage, e.g. - * when a **save-as** action is performed. + * Listener interface for the (current) location of the (current) document of an IDocumentStorage, + * e.g. when a **save-as** action is performed. + * * @author hal * * @param <L> */ public interface IDocumentStorageListener<L> { - /** - * Notifies that the current document location has changed. - * @param documentLocation the new document location - * @param oldDocumentLocation the previous document location - */ - public void documentLocationChanged(L documentLocation, L oldDocumentLocation); + /** + * Notifies that the current document location has changed. + * + * @param documentLocation the new document location + * @param oldDocumentLocation the previous document location + */ + public void documentLocationChanged(L documentLocation, L oldDocumentLocation); } diff --git a/simpleexample/src/main/java/fxutil/doc/SimpleJsonFileStorageImpl.java b/simpleexample/src/main/java/fxutil/doc/SimpleJsonFileStorageImpl.java index 1ad4d73..4f2633c 100644 --- a/simpleexample/src/main/java/fxutil/doc/SimpleJsonFileStorageImpl.java +++ b/simpleexample/src/main/java/fxutil/doc/SimpleJsonFileStorageImpl.java @@ -6,63 +6,63 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.Collection; import java.util.Collections; - import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.module.SimpleModule; -public abstract class SimpleJsonFileStorageImpl<T> extends AbstractDocumentStorageImpl<T, File> implements IDocumentStorage<File> { +public abstract class SimpleJsonFileStorageImpl<T> extends AbstractDocumentStorageImpl<T, File> + implements IDocumentStorage<File> { - private T document; + private T document; - private final ObjectMapper objectMapper; + private final ObjectMapper objectMapper; - private final Class<T> documentClass; + private final Class<T> documentClass; - public SimpleJsonFileStorageImpl(final Class<T> documentClass) { - this.documentClass = documentClass; - final SimpleModule module = new SimpleModule(); - configureJacksonModule(module); - objectMapper = new ObjectMapper(); - objectMapper.registerModule(module); - } + public SimpleJsonFileStorageImpl(final Class<T> documentClass) { + this.documentClass = documentClass; + final SimpleModule module = new SimpleModule(); + configureJacksonModule(module); + objectMapper = new ObjectMapper(); + objectMapper.registerModule(module); + } - protected abstract void configureJacksonModule(final SimpleModule module); + protected abstract void configureJacksonModule(final SimpleModule module); - @Override - public T loadDocument(final InputStream inputStream) throws Exception { - return objectMapper.readValue(inputStream, documentClass); - } + @Override + public T loadDocument(final InputStream inputStream) throws Exception { + return objectMapper.readValue(inputStream, documentClass); + } - @Override - public void saveDocument(final T document, final File documentLocation) throws Exception { - try (OutputStream outputStream = new FileOutputStream(documentLocation, false)) { - objectMapper.writeValue(outputStream, document); - } - } + @Override + public void saveDocument(final T document, final File documentLocation) throws Exception { + try (OutputStream outputStream = new FileOutputStream(documentLocation, false)) { + objectMapper.writeValue(outputStream, document); + } + } - @Override - public Collection<IDocumentImporter> getDocumentImporters() { - return Collections.emptyList(); - } + @Override + public Collection<IDocumentImporter> getDocumentImporters() { + return Collections.emptyList(); + } - @Override - public T getDocument() { - return document; - } + @Override + public T getDocument() { + return document; + } - @Override - public void setDocument(final T document) { - final T oldDocument = this.document; - this.document = document; - fireDocumentChanged(oldDocument); - } + @Override + public void setDocument(final T document) { + final T oldDocument = this.document; + this.document = document; + fireDocumentChanged(oldDocument); + } - @Override - protected T createDocument() { - try { - return documentClass.getDeclaredConstructor().newInstance(); - } catch (final Exception e) { - throw new RuntimeException("Exception when instantiating " + documentClass, e); - } - } + @Override + protected T createDocument() { + try { + return documentClass.getDeclaredConstructor().newInstance(); + } catch (final Exception e) { + throw new RuntimeException("Exception when instantiating " + documentClass, e); + } + } } diff --git a/simpleexample/src/main/java/simpleex/core/LatLong.java b/simpleexample/src/main/java/simpleex/core/LatLong.java index 53ea3af..d699232 100644 --- a/simpleexample/src/main/java/simpleex/core/LatLong.java +++ b/simpleexample/src/main/java/simpleex/core/LatLong.java @@ -2,123 +2,125 @@ package simpleex.core; public class LatLong { - private final double latitude, longitude; - - public LatLong(final double latitude, final double longitude) { - super(); - this.latitude = latitude; - this.longitude = longitude; - } - - public final static String SEPARATOR = ","; - - public double getLatitude() { - return latitude; - } - - public double getLongitude() { - return longitude; - } - - @Override - public String toString() { - return latitude + SEPARATOR + longitude; - } - - @Override - public int hashCode() { - final int prime = 31; - long temp = Double.doubleToLongBits(latitude); - int result = prime + (int) (temp ^ (temp >>> 32)); - temp = Double.doubleToLongBits(longitude); - result = prime * result + (int) (temp ^ (temp >>> 32)); - return result; - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) { - return true; - } - if (obj == null || getClass() != obj.getClass()) { - return false; - } - final LatLong other = (LatLong) obj; - return (Double.doubleToLongBits(latitude) == Double.doubleToLongBits(other.latitude) && - Double.doubleToLongBits(longitude) == Double.doubleToLongBits(other.longitude)); - } - - public static LatLong valueOf(final String s) { - return valueOf(s, SEPARATOR); - } - - public static LatLong valueOf(final String s, final String sep) { - final int pos = s.indexOf(sep); - if (pos < 0) { - throw new IllegalArgumentException("No '" + sep + "' in " + s); - } - final double lat = Double.valueOf(s.substring(0, pos).trim()); - final double lon = Double.valueOf(s.substring(pos + sep.length()).trim()); - - return new LatLong(lat, lon); - } - - /*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ - /*:: :*/ - /*:: This routine calculates the distance between two points (given the :*/ - /*:: latitude/longitude of those points). It is being used to calculate :*/ - /*:: the distance between two locations using GeoDataSource (TM) products :*/ - /*:: :*/ - /*:: Definitions: :*/ - /*:: South latitudes are negative, east longitudes are positive :*/ - /*:: :*/ - /*:: Passed to function: :*/ - /*:: lat1, lon1 = Latitude and Longitude of point 1 (in decimal degrees) :*/ - /*:: lat2, lon2 = Latitude and Longitude of point 2 (in decimal degrees) :*/ - /*:: Worldwide cities and other features databases with latitude longitude :*/ - /*:: are available at http://www.geodatasource.com :*/ - /*:: :*/ - /*:: For enquiries, please contact sales@geodatasource.com :*/ - /*:: :*/ - /*:: Official Web site: http://www.geodatasource.com :*/ - /*:: :*/ - /*:: GeoDataSource.com (C) All Rights Reserved 2015 :*/ - /*:: :*/ - /*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ - public static double distance(final double lat1, final double lon1, final double lat2, final double lon2) { - if (lon1 == lon2 && lat1 == lat2) { - return 0.0; - } - final double theta = lon1 - lon2; - double dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2)) + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(deg2rad(theta)); - dist = Math.acos(dist); - // convert to degrees - dist = rad2deg(dist); - dist = dist * 60 * 1.1515; - // convert to meters - dist = dist * 1609.344; - return dist; - } - - public static double distance(final LatLong latLong1, final LatLong latLong2) { - return distance(latLong1.latitude, latLong1.longitude, latLong2.latitude, latLong2.longitude); - } - - public double distance(final LatLong latLong2) { - return distance(latitude, longitude, latLong2.latitude, latLong2.longitude); - } - - /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ - /*:: This function converts decimal degrees to radians :*/ - /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ - private static double deg2rad(final double deg) { - return (deg * Math.PI / 180.0); - } - - /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ - /*:: This function converts radians to decimal degrees :*/ - /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ - private static double rad2deg(final double rad) { - return (rad * 180 / Math.PI); - } + private final double latitude, longitude; + + public LatLong(final double latitude, final double longitude) { + super(); + this.latitude = latitude; + this.longitude = longitude; + } + + public final static String SEPARATOR = ","; + + public double getLatitude() { + return latitude; + } + + public double getLongitude() { + return longitude; + } + + @Override + public String toString() { + return latitude + SEPARATOR + longitude; + } + + @Override + public int hashCode() { + final int prime = 31; + long temp = Double.doubleToLongBits(latitude); + int result = prime + (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits(longitude); + result = prime * result + (int) (temp ^ (temp >>> 32)); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + final LatLong other = (LatLong) obj; + return (Double.doubleToLongBits(latitude) == Double.doubleToLongBits(other.latitude) + && Double.doubleToLongBits(longitude) == Double.doubleToLongBits(other.longitude)); + } + + public static LatLong valueOf(final String s) { + return valueOf(s, SEPARATOR); + } + + public static LatLong valueOf(final String s, final String sep) { + final int pos = s.indexOf(sep); + if (pos < 0) { + throw new IllegalArgumentException("No '" + sep + "' in " + s); + } + final double lat = Double.valueOf(s.substring(0, pos).trim()); + final double lon = Double.valueOf(s.substring(pos + sep.length()).trim()); + + return new LatLong(lat, lon); + } + + /* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */ + /* :: : */ + /* :: This routine calculates the distance between two points (given the : */ + /* :: latitude/longitude of those points). It is being used to calculate : */ + /* :: the distance between two locations using GeoDataSource (TM) products : */ + /* :: : */ + /* :: Definitions: : */ + /* :: South latitudes are negative, east longitudes are positive : */ + /* :: : */ + /* :: Passed to function: : */ + /* :: lat1, lon1 = Latitude and Longitude of point 1 (in decimal degrees) : */ + /* :: lat2, lon2 = Latitude and Longitude of point 2 (in decimal degrees) : */ + /* :: Worldwide cities and other features databases with latitude longitude : */ + /* :: are available at http://www.geodatasource.com : */ + /* :: : */ + /* :: For enquiries, please contact sales@geodatasource.com : */ + /* :: : */ + /* :: Official Web site: http://www.geodatasource.com : */ + /* :: : */ + /* :: GeoDataSource.com (C) All Rights Reserved 2015 : */ + /* :: : */ + /* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */ + public static double distance(final double lat1, final double lon1, final double lat2, + final double lon2) { + if (lon1 == lon2 && lat1 == lat2) { + return 0.0; + } + final double theta = lon1 - lon2; + double dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2)) + + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(deg2rad(theta)); + dist = Math.acos(dist); + // convert to degrees + dist = rad2deg(dist); + dist = dist * 60 * 1.1515; + // convert to meters + dist = dist * 1609.344; + return dist; + } + + public static double distance(final LatLong latLong1, final LatLong latLong2) { + return distance(latLong1.latitude, latLong1.longitude, latLong2.latitude, latLong2.longitude); + } + + public double distance(final LatLong latLong2) { + return distance(latitude, longitude, latLong2.latitude, latLong2.longitude); + } + + /* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */ + /* :: This function converts decimal degrees to radians : */ + /* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */ + private static double deg2rad(final double deg) { + return (deg * Math.PI / 180.0); + } + + /* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */ + /* :: This function converts radians to decimal degrees : */ + /* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */ + private static double rad2deg(final double rad) { + return (rad * 180 / Math.PI); + } } diff --git a/simpleexample/src/main/java/simpleex/core/LatLongs.java b/simpleexample/src/main/java/simpleex/core/LatLongs.java index 1115017..a5e6fa1 100644 --- a/simpleexample/src/main/java/simpleex/core/LatLongs.java +++ b/simpleexample/src/main/java/simpleex/core/LatLongs.java @@ -7,65 +7,64 @@ import java.util.List; public class LatLongs implements Iterable<LatLong> { - final List<LatLong> latLongs = new ArrayList<>(); - - public LatLongs() { - } - - public LatLongs(final double... latLongsArray) { - addLatLongs(latLongsArray); - } - - public LatLongs(final LatLong... latLongs) { - addLatLongs(latLongs); - } - - public LatLongs(final Collection<LatLong> latLongs) { - addLatLongs(latLongs); - } - - @Override - public Iterator<LatLong> iterator() { - return latLongs.iterator(); - } - - public int getLatLongCount() { - return latLongs.size(); - } - - public LatLong getLatLong(final int num) { - return latLongs.get(num); - } - - public void setLatLong(final int num, final LatLong latLong) { - latLongs.set(num, latLong); - } - - public int addLatLong(final LatLong latLong) { - final int pos = latLongs.size(); - latLongs.add(latLong); - return pos; - } - - public final int addLatLongs(final Collection<LatLong> latLongs) { - final int pos = this.latLongs.size(); - this.latLongs.addAll(latLongs); - return pos; - } - - public final int addLatLongs(final LatLong... latLongs) { - return addLatLongs(List.of(latLongs)); - } - - public final int addLatLongs(final double... latLongsArray) { - final Collection<LatLong> latLongs = new ArrayList<>(latLongsArray.length / 2); - for (int i = 0; i < latLongsArray.length; i += 2) { - latLongs.add(new LatLong(latLongsArray[i], latLongsArray[i + 1])); - } - return addLatLongs(latLongs); - } - - public LatLong removeLatLong(final int num) { - return latLongs.remove(num); - } + final List<LatLong> latLongs = new ArrayList<>(); + + public LatLongs() {} + + public LatLongs(final double... latLongsArray) { + addLatLongs(latLongsArray); + } + + public LatLongs(final LatLong... latLongs) { + addLatLongs(latLongs); + } + + public LatLongs(final Collection<LatLong> latLongs) { + addLatLongs(latLongs); + } + + @Override + public Iterator<LatLong> iterator() { + return latLongs.iterator(); + } + + public int getLatLongCount() { + return latLongs.size(); + } + + public LatLong getLatLong(final int num) { + return latLongs.get(num); + } + + public void setLatLong(final int num, final LatLong latLong) { + latLongs.set(num, latLong); + } + + public int addLatLong(final LatLong latLong) { + final int pos = latLongs.size(); + latLongs.add(latLong); + return pos; + } + + public final int addLatLongs(final Collection<LatLong> latLongs) { + final int pos = this.latLongs.size(); + this.latLongs.addAll(latLongs); + return pos; + } + + public final int addLatLongs(final LatLong... latLongs) { + return addLatLongs(List.of(latLongs)); + } + + public final int addLatLongs(final double... latLongsArray) { + final Collection<LatLong> latLongs = new ArrayList<>(latLongsArray.length / 2); + for (int i = 0; i < latLongsArray.length; i += 2) { + latLongs.add(new LatLong(latLongsArray[i], latLongsArray[i + 1])); + } + return addLatLongs(latLongs); + } + + public LatLong removeLatLong(final int num) { + return latLongs.remove(num); + } } diff --git a/simpleexample/src/main/java/simpleex/json/LatLongDeserializer.java b/simpleexample/src/main/java/simpleex/json/LatLongDeserializer.java index e78c577..f3c48cd 100644 --- a/simpleexample/src/main/java/simpleex/json/LatLongDeserializer.java +++ b/simpleexample/src/main/java/simpleex/json/LatLongDeserializer.java @@ -1,7 +1,6 @@ package simpleex.json; import java.io.IOException; - import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; @@ -9,33 +8,33 @@ import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; - import simpleex.core.LatLong; public class LatLongDeserializer extends JsonDeserializer<LatLong> { - private static final int ARRAY_JSON_NODE_SIZE = 2; + private static final int ARRAY_JSON_NODE_SIZE = 2; - @Override - public LatLong deserialize(final JsonParser jsonParser, final DeserializationContext deserContext) throws IOException, JsonProcessingException { - final JsonNode jsonNode = jsonParser.getCodec().readTree(jsonParser); - return deserialize(jsonNode); - } + @Override + public LatLong deserialize(final JsonParser jsonParser, final DeserializationContext deserContext) + throws IOException, JsonProcessingException { + final JsonNode jsonNode = jsonParser.getCodec().readTree(jsonParser); + return deserialize(jsonNode); + } - public LatLong deserialize(final JsonNode jsonNode) throws JsonProcessingException { - if (jsonNode instanceof ObjectNode) { - final ObjectNode objectNode = (ObjectNode) jsonNode; - final double latitude = objectNode.get(LatLongSerializer.LATITUDE_FIELD_NAME).asDouble(); - final double longitude = objectNode.get(LatLongSerializer.LONGITUDE_FIELD_NAME).asDouble(); - return new LatLong(latitude, longitude); - } else if (jsonNode instanceof ArrayNode) { - final ArrayNode locationArray = (ArrayNode) jsonNode; - if (locationArray.size() == ARRAY_JSON_NODE_SIZE) { - final double latitude = locationArray.get(0).asDouble(); - final double longitude = locationArray.get(1).asDouble(); - return new LatLong(latitude, longitude); - } - } - return null; - } + public LatLong deserialize(final JsonNode jsonNode) throws JsonProcessingException { + if (jsonNode instanceof ObjectNode) { + final ObjectNode objectNode = (ObjectNode) jsonNode; + final double latitude = objectNode.get(LatLongSerializer.LATITUDE_FIELD_NAME).asDouble(); + final double longitude = objectNode.get(LatLongSerializer.LONGITUDE_FIELD_NAME).asDouble(); + return new LatLong(latitude, longitude); + } else if (jsonNode instanceof ArrayNode) { + final ArrayNode locationArray = (ArrayNode) jsonNode; + if (locationArray.size() == ARRAY_JSON_NODE_SIZE) { + final double latitude = locationArray.get(0).asDouble(); + final double longitude = locationArray.get(1).asDouble(); + return new LatLong(latitude, longitude); + } + } + return null; + } } diff --git a/simpleexample/src/main/java/simpleex/json/LatLongSerializer.java b/simpleexample/src/main/java/simpleex/json/LatLongSerializer.java index 0a12779..12342fd 100644 --- a/simpleexample/src/main/java/simpleex/json/LatLongSerializer.java +++ b/simpleexample/src/main/java/simpleex/json/LatLongSerializer.java @@ -1,25 +1,24 @@ package simpleex.json; import java.io.IOException; - import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; - import simpleex.core.LatLong; public class LatLongSerializer extends JsonSerializer<LatLong> { - public static final String LONGITUDE_FIELD_NAME = "longitude"; - public static final String LATITUDE_FIELD_NAME = "latitude"; + public static final String LONGITUDE_FIELD_NAME = "longitude"; + public static final String LATITUDE_FIELD_NAME = "latitude"; - @Override - public void serialize(final LatLong latLon, final JsonGenerator jsonGen, final SerializerProvider provider) throws IOException { - jsonGen.writeStartObject(); - jsonGen.writeFieldName(LATITUDE_FIELD_NAME); - jsonGen.writeNumber(latLon.getLatitude()); - jsonGen.writeFieldName(LONGITUDE_FIELD_NAME); - jsonGen.writeNumber(latLon.getLongitude()); - jsonGen.writeEndObject(); - } + @Override + public void serialize(final LatLong latLon, final JsonGenerator jsonGen, + final SerializerProvider provider) throws IOException { + jsonGen.writeStartObject(); + jsonGen.writeFieldName(LATITUDE_FIELD_NAME); + jsonGen.writeNumber(latLon.getLatitude()); + jsonGen.writeFieldName(LONGITUDE_FIELD_NAME); + jsonGen.writeNumber(latLon.getLongitude()); + jsonGen.writeEndObject(); + } } diff --git a/simpleexample/src/main/java/simpleex/json/LatLongsDeserializer.java b/simpleexample/src/main/java/simpleex/json/LatLongsDeserializer.java index 41232de..4b2508f 100644 --- a/simpleexample/src/main/java/simpleex/json/LatLongsDeserializer.java +++ b/simpleexample/src/main/java/simpleex/json/LatLongsDeserializer.java @@ -3,33 +3,32 @@ package simpleex.json; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; - import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; - import simpleex.core.LatLong; import simpleex.core.LatLongs; public class LatLongsDeserializer extends JsonDeserializer<LatLongs> { - private final LatLongDeserializer latLongDeserializer = new LatLongDeserializer(); + private final LatLongDeserializer latLongDeserializer = new LatLongDeserializer(); - @Override - public LatLongs deserialize(final JsonParser jsonParser, final DeserializationContext deserContext) throws IOException, JsonProcessingException { - final JsonNode jsonNode = jsonParser.getCodec().readTree(jsonParser); - if (jsonNode instanceof ArrayNode) { - final ArrayNode latLongsArray = (ArrayNode) jsonNode; - final Collection<LatLong> latLongs = new ArrayList<>(latLongsArray.size()); - for (final JsonNode latLongNode : latLongsArray) { - final LatLong latLong = latLongDeserializer.deserialize(latLongNode); - latLongs.add(latLong); - } - return new LatLongs(latLongs); - } - return null; - } + @Override + public LatLongs deserialize(final JsonParser jsonParser, + final DeserializationContext deserContext) throws IOException, JsonProcessingException { + final JsonNode jsonNode = jsonParser.getCodec().readTree(jsonParser); + if (jsonNode instanceof ArrayNode) { + final ArrayNode latLongsArray = (ArrayNode) jsonNode; + final Collection<LatLong> latLongs = new ArrayList<>(latLongsArray.size()); + for (final JsonNode latLongNode : latLongsArray) { + final LatLong latLong = latLongDeserializer.deserialize(latLongNode); + latLongs.add(latLong); + } + return new LatLongs(latLongs); + } + return null; + } } diff --git a/simpleexample/src/main/java/simpleex/json/LatLongsSerializer.java b/simpleexample/src/main/java/simpleex/json/LatLongsSerializer.java index d39fec5..8f5bae8 100644 --- a/simpleexample/src/main/java/simpleex/json/LatLongsSerializer.java +++ b/simpleexample/src/main/java/simpleex/json/LatLongsSerializer.java @@ -1,22 +1,21 @@ package simpleex.json; import java.io.IOException; - import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; - import simpleex.core.LatLong; import simpleex.core.LatLongs; public class LatLongsSerializer extends JsonSerializer<LatLongs> { - @Override - public void serialize(final LatLongs latLongs, final JsonGenerator jsonGen, final SerializerProvider provider) throws IOException { - jsonGen.writeStartArray(latLongs.getLatLongCount()); - for (final LatLong latLong : latLongs) { - jsonGen.writeObject(latLong); - } - jsonGen.writeEndArray(); - } + @Override + public void serialize(final LatLongs latLongs, final JsonGenerator jsonGen, + final SerializerProvider provider) throws IOException { + jsonGen.writeStartArray(latLongs.getLatLongCount()); + for (final LatLong latLong : latLongs) { + jsonGen.writeObject(latLong); + } + jsonGen.writeEndArray(); + } } diff --git a/simpleexample/src/main/java/simpleex/ui/DraggableNodeController.java b/simpleexample/src/main/java/simpleex/ui/DraggableNodeController.java index ed68938..8ff284c 100644 --- a/simpleexample/src/main/java/simpleex/ui/DraggableNodeController.java +++ b/simpleexample/src/main/java/simpleex/ui/DraggableNodeController.java @@ -1,7 +1,6 @@ package simpleex.ui; import java.util.Optional; - import javafx.event.EventHandler; import javafx.geometry.Point2D; import javafx.scene.Node; @@ -9,89 +8,89 @@ import javafx.scene.input.MouseEvent; public class DraggableNodeController { - public DraggableNodeController() { - } - - public DraggableNodeController(final Optional<NodeDraggedHandler> nodeDraggedHandler) { - setNodeDraggedHandler(nodeDraggedHandler); - } - - private Optional<NodeDraggedHandler> nodeDraggedHandler = Optional.empty(); - - public final void setNodeDraggedHandler(final Optional<NodeDraggedHandler> nodeDraggedHandler) { - this.nodeDraggedHandler = nodeDraggedHandler; - } - - private boolean immediate = false; - - public void setImmediate(final boolean immediate) { - this.immediate = immediate; - } - - private Optional<Node> currentNode = Optional.empty(); - private Point2D startPoint = null; - private Point2D startTranslate = null; - - private final EventHandler<MouseEvent> mousePressedHandler = this::mousePressed; - private final EventHandler<MouseEvent> mouseDraggedHandler = this::mouseDragged; - private final EventHandler<MouseEvent> mouseReleasedHandler = this::mouseReleased; - - public void attach(final Node node) { - node.setOnMousePressed(mousePressedHandler); - node.setOnMouseDragged(mouseDraggedHandler); - node.setOnMouseReleased(mouseReleasedHandler); - } - - public void detach(final Node node) { - node.setOnMousePressed(null); - node.setOnMouseDragged(null); - node.setOnMouseReleased(null); - } - - private void mousePressed(final MouseEvent mouseEvent) { - if (currentNode.isEmpty() && mouseEvent.getSource() instanceof Node) { - currentNode = Optional.of((Node) mouseEvent.getSource()); - startPoint = new Point2D(mouseEvent.getSceneX(), mouseEvent.getSceneY()); - startTranslate = new Point2D(currentNode.get().getTranslateX(), currentNode.get().getTranslateY()); - mouseEvent.consume(); - } - } - - private void mouseDragged(final MouseEvent mouseEvent) { - if (currentNode.isPresent() && currentNode.get() == mouseEvent.getSource()) { - final double dx = mouseEvent.getSceneX() - startPoint.getX(); - final double dy = mouseEvent.getSceneY() - startPoint.getY(); - updateNode(dx, dy); - } - } - - protected void updateNode(final double dx, final double dy) { - if (immediate && nodeDraggedHandler.isPresent()) { - nodeDraggedHandler.get().nodeDragged(currentNode.get(), dx, dy); - startPoint = startPoint.add(dx, dy); - } else if (currentNode.isPresent()) { - currentNode.get().setTranslateX(startTranslate.getX() + dx); - currentNode.get().setTranslateY(startTranslate.getY() + dy); - } - } - - private void mouseReleased(final MouseEvent mouseEvent) { - if (currentNode.isPresent() && currentNode.get() == mouseEvent.getSource()) { - final double dx = mouseEvent.getSceneX() - startPoint.getX(); - final double dy = mouseEvent.getSceneY() - startPoint.getY(); - if (! immediate) { - currentNode.get().setTranslateX(startTranslate.getX()); - currentNode.get().setTranslateY(startTranslate.getY()); - } - final Node node = currentNode.get(); - currentNode = Optional.empty(); - if (nodeDraggedHandler.isPresent()) { - nodeDraggedHandler.get().nodeDragged(node, dx, dy); - } - } - } - - public interface NodeDraggedHandler { - public void nodeDragged(Node currentNode2, double dx, double dy); - } + public DraggableNodeController() {} + + public DraggableNodeController(final Optional<NodeDraggedHandler> nodeDraggedHandler) { + setNodeDraggedHandler(nodeDraggedHandler); + } + + private Optional<NodeDraggedHandler> nodeDraggedHandler = Optional.empty(); + + public final void setNodeDraggedHandler(final Optional<NodeDraggedHandler> nodeDraggedHandler) { + this.nodeDraggedHandler = nodeDraggedHandler; + } + + private boolean immediate = false; + + public void setImmediate(final boolean immediate) { + this.immediate = immediate; + } + + private Optional<Node> currentNode = Optional.empty(); + private Point2D startPoint = null; + private Point2D startTranslate = null; + + private final EventHandler<MouseEvent> mousePressedHandler = this::mousePressed; + private final EventHandler<MouseEvent> mouseDraggedHandler = this::mouseDragged; + private final EventHandler<MouseEvent> mouseReleasedHandler = this::mouseReleased; + + public void attach(final Node node) { + node.setOnMousePressed(mousePressedHandler); + node.setOnMouseDragged(mouseDraggedHandler); + node.setOnMouseReleased(mouseReleasedHandler); + } + + public void detach(final Node node) { + node.setOnMousePressed(null); + node.setOnMouseDragged(null); + node.setOnMouseReleased(null); + } + + private void mousePressed(final MouseEvent mouseEvent) { + if (currentNode.isEmpty() && mouseEvent.getSource() instanceof Node) { + currentNode = Optional.of((Node) mouseEvent.getSource()); + startPoint = new Point2D(mouseEvent.getSceneX(), mouseEvent.getSceneY()); + startTranslate = + new Point2D(currentNode.get().getTranslateX(), currentNode.get().getTranslateY()); + mouseEvent.consume(); + } + } + + private void mouseDragged(final MouseEvent mouseEvent) { + if (currentNode.isPresent() && currentNode.get() == mouseEvent.getSource()) { + final double dx = mouseEvent.getSceneX() - startPoint.getX(); + final double dy = mouseEvent.getSceneY() - startPoint.getY(); + updateNode(dx, dy); + } + } + + protected void updateNode(final double dx, final double dy) { + if (immediate && nodeDraggedHandler.isPresent()) { + nodeDraggedHandler.get().nodeDragged(currentNode.get(), dx, dy); + startPoint = startPoint.add(dx, dy); + } else if (currentNode.isPresent()) { + currentNode.get().setTranslateX(startTranslate.getX() + dx); + currentNode.get().setTranslateY(startTranslate.getY() + dy); + } + } + + private void mouseReleased(final MouseEvent mouseEvent) { + if (currentNode.isPresent() && currentNode.get() == mouseEvent.getSource()) { + final double dx = mouseEvent.getSceneX() - startPoint.getX(); + final double dy = mouseEvent.getSceneY() - startPoint.getY(); + if (!immediate) { + currentNode.get().setTranslateX(startTranslate.getX()); + currentNode.get().setTranslateY(startTranslate.getY()); + } + final Node node = currentNode.get(); + currentNode = Optional.empty(); + if (nodeDraggedHandler.isPresent()) { + nodeDraggedHandler.get().nodeDragged(node, dx, dy); + } + } + } + + public interface NodeDraggedHandler { + public void nodeDragged(Node currentNode2, double dx, double dy); + } } diff --git a/simpleexample/src/main/java/simpleex/ui/FxApp.java b/simpleexample/src/main/java/simpleex/ui/FxApp.java index 5ab8183..a776467 100644 --- a/simpleexample/src/main/java/simpleex/ui/FxApp.java +++ b/simpleexample/src/main/java/simpleex/ui/FxApp.java @@ -9,23 +9,23 @@ import simpleex.core.LatLongs; public class FxApp extends Application { - @Override - public void start(final Stage stage) throws Exception { - final FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("FxApp.fxml")); - final Parent root = fxmlLoader.load(); - final FxAppController controller = fxmlLoader.getController(); - controller.setLatLongs(new LatLongs(63.1, 11.2, 63.2, 11.0)); - final Scene scene = new Scene(root); - stage.setScene(scene); - stage.show(); - } + @Override + public void start(final Stage stage) throws Exception { + final FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("FxApp.fxml")); + final Parent root = fxmlLoader.load(); + final FxAppController controller = fxmlLoader.getController(); + controller.setLatLongs(new LatLongs(63.1, 11.2, 63.2, 11.0)); + final Scene scene = new Scene(root); + stage.setScene(scene); + stage.show(); + } - public static void main(final String[] args) { - // only needed on ios - System.setProperty("os.target", "ios"); - System.setProperty("os.name", "iOS"); - System.setProperty("glass.platform", "ios"); - System.setProperty("targetos.name", "iOS"); - launch(args); - } + public static void main(final String[] args) { + // only needed on ios + System.setProperty("os.target", "ios"); + System.setProperty("os.name", "iOS"); + System.setProperty("glass.platform", "ios"); + System.setProperty("targetos.name", "iOS"); + launch(args); + } } diff --git a/simpleexample/src/main/java/simpleex/ui/FxAppController.java b/simpleexample/src/main/java/simpleex/ui/FxAppController.java index b8968b6..08431b7 100644 --- a/simpleexample/src/main/java/simpleex/ui/FxAppController.java +++ b/simpleexample/src/main/java/simpleex/ui/FxAppController.java @@ -2,7 +2,6 @@ package simpleex.ui; import java.io.File; import java.util.Optional; - import fxmapcontrol.Location; import fxmapcontrol.MapBase; import fxmapcontrol.MapItemsControl; @@ -19,147 +18,151 @@ import javafx.scene.control.Slider; import simpleex.core.LatLong; import simpleex.core.LatLongs; -public class FxAppController extends FileMenuController implements IDocumentListener<LatLongs, File> { - - private final LatLongsStorage latLongsStorage; - - public FxAppController() { - latLongsStorage = new LatLongsStorage(); - latLongsStorage.addDocumentStorageListener(this); - } - - public LatLongs getLatLongs() { - return latLongsStorage.getDocument(); - } - - // to make it testable - public void setLatLongs(final LatLongs latLongs) { - latLongsStorage.setDocument(latLongs); - updateLocationViewList(0); - } - - // @FXML - // private FileMenuController fileMenuController; - - @FXML - private ListView<LatLong> locationListView; - - @FXML - private MapBase mapView; - - private MapItemsControl<MapNode> markersParent; - private Optional<MapMarker> marker = Optional.empty(); - private DraggableNodeController draggableMapController = null; - private DraggableNodeController draggableMarkerController = null; - - @FXML - private Slider zoomSlider; - - @FXML - private void initialize() { - // fileMenuController. - setDocumentStorage(latLongsStorage); - // map stuff - // mapView.getChildren().add(MapTileLayer.getOpenStreetMapLayer()); - zoomSlider.valueProperty().addListener((prop, oldValue, newValue) -> mapView.setZoomLevel(zoomSlider.getValue())); - zoomSlider.setValue(8); - markersParent = new MapItemsControl<MapNode>(); - mapView.getChildren().add(markersParent); - draggableMapController = new DraggableNodeController(Optional.of(this::handleMapDragged)); - draggableMapController.setImmediate(true); - draggableMapController.attach(mapView); - draggableMarkerController = new DraggableNodeController(Optional.of(this::handleMarkerDragged)); - // the location list - locationListView.getSelectionModel().selectedIndexProperty().addListener((prop, oldValue, newValue) -> updateMapMarker(true)); - } - - private void handleMapDragged(final Node node, final double dx, final double dy) { - final MapProjection projection = mapView.getProjection(); - final Point2D point = projection.locationToViewportPoint(mapView.getCenter()); - final Location newCenter = projection.viewportPointToLocation(point.add(-dx, -dy)); - mapView.setCenter(newCenter); - } - - private void handleMarkerDragged(final Node node, final double dx, final double dy) { - final MapProjection projection = mapView.getProjection(); - final Point2D point = projection.locationToViewportPoint(marker.get().getLocation()); - final Location newLocation = projection.viewportPointToLocation(point.add(dx, dy)); - getLatLongs().setLatLong(locationListView.getSelectionModel().getSelectedIndex(), location2LatLong(newLocation)); - updateLocationViewListSelection(false); - } - - private LatLong location2LatLong(final Location newLocation) { - return new LatLong(newLocation.getLatitude(), newLocation.getLongitude()); - } - - private void updateMapMarker(final boolean centerOnMarker) { - final int num = locationListView.getSelectionModel().getSelectedIndex(); - if (num < 0 || num >= getLatLongs().getLatLongCount()) { - markersParent.getItems().clear(); - if (draggableMarkerController != null) { - draggableMarkerController.detach(marker.get()); - } - marker = Optional.empty(); - } else { - final LatLong latLong = getLatLongs().getLatLong(num); - if (marker.isEmpty()) { - final MapMarker aMarker = new MapMarker(latLong); - markersParent.getItems().add(aMarker); - if (draggableMarkerController != null) { - draggableMarkerController.attach(aMarker); - } - marker = Optional.of(aMarker); - } else { - marker.get().setLocation(latLong); - } - if (centerOnMarker) { - mapView.setCenter(marker.get().getLocation()); - } - } - } - - @FXML - private void handleAddLocation() { - final Location center = mapView.getCenter(); - final int pos = getLatLongs().addLatLong(location2LatLong(center)); - updateLocationViewList(pos); - } - - private void updateLocationViewListSelection(final Boolean updateMapMarker) { - final int selectedIndex = locationListView.getSelectionModel().getSelectedIndex(); - updateLocationViewListItem(selectedIndex); - if (updateMapMarker != null) { - updateMapMarker(updateMapMarker); - } - } - - private void updateLocationViewListItem(final int index) { - locationListView.getItems().set(index, getLatLongs().getLatLong(index)); - } - - private void updateLocationViewList(int selectedIndex) { - final LatLong[] latLongs = new LatLong[getLatLongs().getLatLongCount()]; - for (int i = 0; i < latLongs.length; i++) { - latLongs[i] = getLatLongs().getLatLong(i); - } - final int oldSelectionIndex = locationListView.getSelectionModel().getSelectedIndex(); - locationListView.setItems(FXCollections.observableArrayList(latLongs)); - if (selectedIndex < 0 || selectedIndex >= latLongs.length) { - selectedIndex = oldSelectionIndex; - } - if (selectedIndex >= 0 && selectedIndex < getLatLongs().getLatLongCount()) { - locationListView.getSelectionModel().select(selectedIndex); - } - } - - // IDocumentListener - - @Override - public void documentLocationChanged(final File documentLocation, final File oldDocumentLocation) { - } - - @Override - public void documentChanged(final LatLongs document, final LatLongs oldDocument) { - updateLocationViewList(0); - } +public class FxAppController extends FileMenuController + implements IDocumentListener<LatLongs, File> { + + private final LatLongsStorage latLongsStorage; + + public FxAppController() { + latLongsStorage = new LatLongsStorage(); + latLongsStorage.addDocumentStorageListener(this); + } + + public LatLongs getLatLongs() { + return latLongsStorage.getDocument(); + } + + // to make it testable + public void setLatLongs(final LatLongs latLongs) { + latLongsStorage.setDocument(latLongs); + updateLocationViewList(0); + } + + // @FXML + // private FileMenuController fileMenuController; + + @FXML + private ListView<LatLong> locationListView; + + @FXML + private MapBase mapView; + + private MapItemsControl<MapNode> markersParent; + private Optional<MapMarker> marker = Optional.empty(); + private DraggableNodeController draggableMapController = null; + private DraggableNodeController draggableMarkerController = null; + + @FXML + private Slider zoomSlider; + + @FXML + private void initialize() { + // fileMenuController. + setDocumentStorage(latLongsStorage); + // map stuff + // mapView.getChildren().add(MapTileLayer.getOpenStreetMapLayer()); + zoomSlider.valueProperty() + .addListener((prop, oldValue, newValue) -> mapView.setZoomLevel(zoomSlider.getValue())); + zoomSlider.setValue(8); + markersParent = new MapItemsControl<MapNode>(); + mapView.getChildren().add(markersParent); + draggableMapController = new DraggableNodeController(Optional.of(this::handleMapDragged)); + draggableMapController.setImmediate(true); + draggableMapController.attach(mapView); + draggableMarkerController = new DraggableNodeController(Optional.of(this::handleMarkerDragged)); + // the location list + locationListView.getSelectionModel().selectedIndexProperty() + .addListener((prop, oldValue, newValue) -> updateMapMarker(true)); + } + + private void handleMapDragged(final Node node, final double dx, final double dy) { + final MapProjection projection = mapView.getProjection(); + final Point2D point = projection.locationToViewportPoint(mapView.getCenter()); + final Location newCenter = projection.viewportPointToLocation(point.add(-dx, -dy)); + mapView.setCenter(newCenter); + } + + private void handleMarkerDragged(final Node node, final double dx, final double dy) { + final MapProjection projection = mapView.getProjection(); + final Point2D point = projection.locationToViewportPoint(marker.get().getLocation()); + final Location newLocation = projection.viewportPointToLocation(point.add(dx, dy)); + getLatLongs().setLatLong(locationListView.getSelectionModel().getSelectedIndex(), + location2LatLong(newLocation)); + updateLocationViewListSelection(false); + } + + private LatLong location2LatLong(final Location newLocation) { + return new LatLong(newLocation.getLatitude(), newLocation.getLongitude()); + } + + private void updateMapMarker(final boolean centerOnMarker) { + final int num = locationListView.getSelectionModel().getSelectedIndex(); + if (num < 0 || num >= getLatLongs().getLatLongCount()) { + markersParent.getItems().clear(); + if (draggableMarkerController != null) { + draggableMarkerController.detach(marker.get()); + } + marker = Optional.empty(); + } else { + final LatLong latLong = getLatLongs().getLatLong(num); + if (marker.isEmpty()) { + final MapMarker aMarker = new MapMarker(latLong); + markersParent.getItems().add(aMarker); + if (draggableMarkerController != null) { + draggableMarkerController.attach(aMarker); + } + marker = Optional.of(aMarker); + } else { + marker.get().setLocation(latLong); + } + if (centerOnMarker) { + mapView.setCenter(marker.get().getLocation()); + } + } + } + + @FXML + private void handleAddLocation() { + final Location center = mapView.getCenter(); + final int pos = getLatLongs().addLatLong(location2LatLong(center)); + updateLocationViewList(pos); + } + + private void updateLocationViewListSelection(final Boolean updateMapMarker) { + final int selectedIndex = locationListView.getSelectionModel().getSelectedIndex(); + updateLocationViewListItem(selectedIndex); + if (updateMapMarker != null) { + updateMapMarker(updateMapMarker); + } + } + + private void updateLocationViewListItem(final int index) { + locationListView.getItems().set(index, getLatLongs().getLatLong(index)); + } + + private void updateLocationViewList(int selectedIndex) { + final LatLong[] latLongs = new LatLong[getLatLongs().getLatLongCount()]; + for (int i = 0; i < latLongs.length; i++) { + latLongs[i] = getLatLongs().getLatLong(i); + } + final int oldSelectionIndex = locationListView.getSelectionModel().getSelectedIndex(); + locationListView.setItems(FXCollections.observableArrayList(latLongs)); + if (selectedIndex < 0 || selectedIndex >= latLongs.length) { + selectedIndex = oldSelectionIndex; + } + if (selectedIndex >= 0 && selectedIndex < getLatLongs().getLatLongCount()) { + locationListView.getSelectionModel().select(selectedIndex); + } + } + + // IDocumentListener + + @Override + public void documentLocationChanged(final File documentLocation, + final File oldDocumentLocation) {} + + @Override + public void documentChanged(final LatLongs document, final LatLongs oldDocument) { + updateLocationViewList(0); + } } diff --git a/simpleexample/src/main/java/simpleex/ui/LatLongsApp.java b/simpleexample/src/main/java/simpleex/ui/LatLongsApp.java index 6436b5d..53a4a53 100644 --- a/simpleexample/src/main/java/simpleex/ui/LatLongsApp.java +++ b/simpleexample/src/main/java/simpleex/ui/LatLongsApp.java @@ -9,7 +9,6 @@ import java.io.OutputStream; import java.util.Arrays; import java.util.Collection; import java.util.stream.Collectors; - import fxutil.doc.AbstractDocumentStorageImpl; import fxutil.doc.IDocumentImporter; import fxutil.doc.IDocumentLoader; @@ -19,80 +18,84 @@ import simpleex.core.LatLongs; public class LatLongsApp { - private LatLongs latLongs = null; - - private final IDocumentPersistence<LatLongs, File> documentPersistence = new IDocumentPersistence<LatLongs, File>() { - - @Override - public LatLongs loadDocument(final InputStream inputStream) throws Exception { - // TODO - return null; - } - - @Override - public void saveDocument(final LatLongs document, final File documentLocation) throws Exception { - try (OutputStream output = new FileOutputStream(documentLocation)) { - // TODO - } - } - }; - - private final AbstractDocumentStorageImpl<LatLongs, File> documentStorage = new AbstractDocumentStorageImpl<LatLongs, File>() { - - @Override - protected LatLongs getDocument() { - return latLongs; - } - - @Override - protected void setDocument(final LatLongs document) { - final LatLongs oldDocument = getDocument(); - LatLongsApp.this.latLongs = document; - fireDocumentChanged(oldDocument); - } - - @Override - protected LatLongs createDocument() { - return new LatLongs(); - } - - @Override - protected InputStream toInputStream(final File storage) throws IOException { - return new FileInputStream(storage); - } - - @Override - public LatLongs loadDocument(final InputStream inputStream) throws Exception { - return documentPersistence.loadDocument(inputStream); - } - - @Override - public void saveDocument(final LatLongs document, final File documentLocation) throws Exception { - documentPersistence.saveDocument(document, documentLocation); - } - - @Override - public Collection<IDocumentImporter> getDocumentImporters() { - return documentLoaders.stream().map(loader -> new IDocumentImporter() { - @Override - public void importDocument(final InputStream inputStream) throws IOException { - try { - setDocumentAndLocation(loader.loadDocument(inputStream), null); - } catch (final Exception e) { - throw new IOException(e); - } - } - }).collect(Collectors.toList()); - } - }; - - public IDocumentStorage<File> getDocumentStorage() { - return documentStorage; - } - - private final Collection<IDocumentLoader<LatLongs>> documentLoaders = Arrays.asList(); - - public Iterable<IDocumentLoader<LatLongs>> getDocumentLoaders() { - return documentLoaders; - } + private LatLongs latLongs = null; + + private final IDocumentPersistence<LatLongs, File> documentPersistence = + new IDocumentPersistence<LatLongs, File>() { + + @Override + public LatLongs loadDocument(final InputStream inputStream) throws Exception { + // TODO + return null; + } + + @Override + public void saveDocument(final LatLongs document, final File documentLocation) + throws Exception { + try (OutputStream output = new FileOutputStream(documentLocation)) { + // TODO + } + } + }; + + private final AbstractDocumentStorageImpl<LatLongs, File> documentStorage = + new AbstractDocumentStorageImpl<LatLongs, File>() { + + @Override + protected LatLongs getDocument() { + return latLongs; + } + + @Override + protected void setDocument(final LatLongs document) { + final LatLongs oldDocument = getDocument(); + LatLongsApp.this.latLongs = document; + fireDocumentChanged(oldDocument); + } + + @Override + protected LatLongs createDocument() { + return new LatLongs(); + } + + @Override + protected InputStream toInputStream(final File storage) throws IOException { + return new FileInputStream(storage); + } + + @Override + public LatLongs loadDocument(final InputStream inputStream) throws Exception { + return documentPersistence.loadDocument(inputStream); + } + + @Override + public void saveDocument(final LatLongs document, final File documentLocation) + throws Exception { + documentPersistence.saveDocument(document, documentLocation); + } + + @Override + public Collection<IDocumentImporter> getDocumentImporters() { + return documentLoaders.stream().map(loader -> new IDocumentImporter() { + @Override + public void importDocument(final InputStream inputStream) throws IOException { + try { + setDocumentAndLocation(loader.loadDocument(inputStream), null); + } catch (final Exception e) { + throw new IOException(e); + } + } + }).collect(Collectors.toList()); + } + }; + + public IDocumentStorage<File> getDocumentStorage() { + return documentStorage; + } + + private final Collection<IDocumentLoader<LatLongs>> documentLoaders = Arrays.asList(); + + public Iterable<IDocumentLoader<LatLongs>> getDocumentLoaders() { + return documentLoaders; + } } diff --git a/simpleexample/src/main/java/simpleex/ui/LatLongsStorage.java b/simpleexample/src/main/java/simpleex/ui/LatLongsStorage.java index 53e108b..de1caf1 100644 --- a/simpleexample/src/main/java/simpleex/ui/LatLongsStorage.java +++ b/simpleexample/src/main/java/simpleex/ui/LatLongsStorage.java @@ -1,9 +1,7 @@ package simpleex.ui; import java.io.File; - import com.fasterxml.jackson.databind.module.SimpleModule; - import fxutil.doc.IDocumentStorage; import fxutil.doc.SimpleJsonFileStorageImpl; import simpleex.core.LatLong; @@ -13,17 +11,18 @@ import simpleex.json.LatLongSerializer; import simpleex.json.LatLongsDeserializer; import simpleex.json.LatLongsSerializer; -public class LatLongsStorage extends SimpleJsonFileStorageImpl<LatLongs> implements IDocumentStorage<File> { +public class LatLongsStorage extends SimpleJsonFileStorageImpl<LatLongs> + implements IDocumentStorage<File> { - public LatLongsStorage() { - super(LatLongs.class); - } + public LatLongsStorage() { + super(LatLongs.class); + } - @Override - protected void configureJacksonModule(final SimpleModule module) { - module.addSerializer(LatLong.class, new LatLongSerializer()); - module.addSerializer(LatLongs.class, new LatLongsSerializer()); - module.addDeserializer(LatLong.class, new LatLongDeserializer()); - module.addDeserializer(LatLongs.class, new LatLongsDeserializer()); - } + @Override + protected void configureJacksonModule(final SimpleModule module) { + module.addSerializer(LatLong.class, new LatLongSerializer()); + module.addSerializer(LatLongs.class, new LatLongsSerializer()); + module.addDeserializer(LatLong.class, new LatLongDeserializer()); + module.addDeserializer(LatLongs.class, new LatLongsDeserializer()); + } } diff --git a/simpleexample/src/main/java/simpleex/ui/MapMarker.java b/simpleexample/src/main/java/simpleex/ui/MapMarker.java index a2365b7..47ece58 100644 --- a/simpleexample/src/main/java/simpleex/ui/MapMarker.java +++ b/simpleexample/src/main/java/simpleex/ui/MapMarker.java @@ -8,15 +8,15 @@ import simpleex.core.LatLong; public class MapMarker extends MapItem<LatLong> { - public MapMarker(final LatLong latLong) { - setLocation(latLong); - final Circle circle = new Circle(); - circle.setRadius(5); - circle.setFill(Color.BLUE); - getChildren().add(circle); - } + public MapMarker(final LatLong latLong) { + setLocation(latLong); + final Circle circle = new Circle(); + circle.setRadius(5); + circle.setFill(Color.BLUE); + getChildren().add(circle); + } - public final void setLocation(final LatLong latLong) { - setLocation(new Location(latLong.getLatitude(), latLong.getLongitude())); - } + public final void setLocation(final LatLong latLong) { + setLocation(new Location(latLong.getLatitude(), latLong.getLongitude())); + } } diff --git a/simpleexample/src/test/java/simpleex/core/LatLongTest.java b/simpleexample/src/test/java/simpleex/core/LatLongTest.java index 3b055dd..2931ac3 100644 --- a/simpleexample/src/test/java/simpleex/core/LatLongTest.java +++ b/simpleexample/src/test/java/simpleex/core/LatLongTest.java @@ -2,70 +2,69 @@ package simpleex.core; import java.util.HashMap; import java.util.Map; - import org.junit.Assert; import org.junit.Test; public class LatLongTest { - @Test - public void testToString() { - final LatLong latLong = new LatLong(63.0, 10.0); - Assert.assertEquals(Double.toString(63) + "," + Double.toString(10), latLong.toString()); - } + @Test + public void testToString() { + final LatLong latLong = new LatLong(63.0, 10.0); + Assert.assertEquals(Double.toString(63) + "," + Double.toString(10), latLong.toString()); + } - @Test - public void testValueOf() { - testLatLong(LatLong.valueOf("63.0, 10.0"), 63.0, 10.0); - testLatLong(LatLong.valueOf("63.0, 10.0", ","), 63.0, 10.0); - testLatLong(LatLong.valueOf("63.0; 10.0", ";"), 63.0, 10.0); - try { - testLatLong(LatLong.valueOf("63.0; 10.0", ","), 63.0, 10.0); - Assert.fail("Should throw IllegalArgumentException"); - } catch (final IllegalArgumentException e) { - } catch (final Exception e) { - Assert.fail("Should throw IllegalArgumentException"); - } - } + @Test + public void testValueOf() { + testLatLong(LatLong.valueOf("63.0, 10.0"), 63.0, 10.0); + testLatLong(LatLong.valueOf("63.0, 10.0", ","), 63.0, 10.0); + testLatLong(LatLong.valueOf("63.0; 10.0", ";"), 63.0, 10.0); + try { + testLatLong(LatLong.valueOf("63.0; 10.0", ","), 63.0, 10.0); + Assert.fail("Should throw IllegalArgumentException"); + } catch (final IllegalArgumentException e) { + } catch (final Exception e) { + Assert.fail("Should throw IllegalArgumentException"); + } + } - private void testLatLong(final LatLong latLong, final double lat, final double lon) { - Assert.assertEquals(lat, latLong.getLatitude(), 0.0); - Assert.assertEquals(lon, latLong.getLongitude(), 0.0); - } + private void testLatLong(final LatLong latLong, final double lat, final double lon) { + Assert.assertEquals(lat, latLong.getLatitude(), 0.0); + Assert.assertEquals(lon, latLong.getLongitude(), 0.0); + } - @Test - public void testEquals() { - Assert.assertTrue(new LatLong(63.0, 10.0).equals(new LatLong(63.0, 10.0))); - Assert.assertFalse(new LatLong(10.0, 63.0).equals(new LatLong(63.0, 10.0))); - Assert.assertFalse(new LatLong(10.0, 63.0).equals(null)); - } + @Test + public void testEquals() { + Assert.assertTrue(new LatLong(63.0, 10.0).equals(new LatLong(63.0, 10.0))); + Assert.assertFalse(new LatLong(10.0, 63.0).equals(new LatLong(63.0, 10.0))); + Assert.assertFalse(new LatLong(10.0, 63.0).equals(null)); + } - @Test - public void testHashCode() { - final Map<LatLong, String> map = new HashMap<>(); - map.put(new LatLong(63.0, 10.0), "first"); - map.put(new LatLong(63.0, 10.0), "second"); - Assert.assertEquals(1, map.size()); - Assert.assertEquals("second", map.get(new LatLong(63.0, 10.0))); - } + @Test + public void testHashCode() { + final Map<LatLong, String> map = new HashMap<>(); + map.put(new LatLong(63.0, 10.0), "first"); + map.put(new LatLong(63.0, 10.0), "second"); + Assert.assertEquals(1, map.size()); + Assert.assertEquals("second", map.get(new LatLong(63.0, 10.0))); + } - @Test - public void testDistance() { - final LatLong trd = new LatLong(63.4217137055, 10.4221522734); - final LatLong str = new LatLong(63.0339713594, 10.2946225585); + @Test + public void testDistance() { + final LatLong trd = new LatLong(63.4217137055, 10.4221522734); + final LatLong str = new LatLong(63.0339713594, 10.2946225585); - checkDistance(trd.distance(trd), 0.0, 10.0); - checkDistance(str.distance(str), 0.0, 10.0); - checkDistance(trd.distance(str), 43000.0, 45000.0); - checkDistance(str.distance(trd), 43000.0, 45000.0); + checkDistance(trd.distance(trd), 0.0, 10.0); + checkDistance(str.distance(str), 0.0, 10.0); + checkDistance(trd.distance(str), 43000.0, 45000.0); + checkDistance(str.distance(trd), 43000.0, 45000.0); - checkDistance(LatLong.distance(trd, trd), 0.0, 10.0); - checkDistance(LatLong.distance(str, str), 0.0, 10.0); - checkDistance(LatLong.distance(trd, str), 43000.0, 45000.0); - checkDistance(LatLong.distance(str, trd), 43000.0, 45000.0); - } + checkDistance(LatLong.distance(trd, trd), 0.0, 10.0); + checkDistance(LatLong.distance(str, str), 0.0, 10.0); + checkDistance(LatLong.distance(trd, str), 43000.0, 45000.0); + checkDistance(LatLong.distance(str, trd), 43000.0, 45000.0); + } - private void checkDistance(final double d, final double lower, final double upper) { - Assert.assertTrue(d + " isn't between " + lower + " and " + upper, d <= upper && d >= lower); - } + private void checkDistance(final double d, final double lower, final double upper) { + Assert.assertTrue(d + " isn't between " + lower + " and " + upper, d <= upper && d >= lower); + } } diff --git a/simpleexample/src/test/java/simpleex/core/LatLongsTest.java b/simpleexample/src/test/java/simpleex/core/LatLongsTest.java index 6995346..dee7f31 100644 --- a/simpleexample/src/test/java/simpleex/core/LatLongsTest.java +++ b/simpleexample/src/test/java/simpleex/core/LatLongsTest.java @@ -2,63 +2,65 @@ package simpleex.core; import java.util.Arrays; import java.util.Iterator; - import org.junit.Assert; import org.junit.Before; import org.junit.Test; public class LatLongsTest { - private LatLongs latLongs; + private LatLongs latLongs; - @Before - public void setUp() { - latLongs = new LatLongs(); - } + @Before + public void setUp() { + latLongs = new LatLongs(); + } - @Test - public void testEmptyConstructor() { - Assert.assertEquals(0, latLongs.getLatLongCount()); - } + @Test + public void testEmptyConstructor() { + Assert.assertEquals(0, latLongs.getLatLongCount()); + } - private static void checkLatLongs(final LatLongs latLongs1, final LatLong... latLongs2) { - Assert.assertEquals(latLongs2.length, latLongs1.getLatLongCount()); - final Iterator<LatLong> it = latLongs1.iterator(); - for (int i = 0; i < latLongs2.length; i++) { - Assert.assertTrue(it.hasNext()); - Assert.assertEquals(latLongs2[i], latLongs1.getLatLong(i)); - Assert.assertEquals(latLongs2[i], it.next()); - } - Assert.assertFalse(it.hasNext()); - } + private static void checkLatLongs(final LatLongs latLongs1, final LatLong... latLongs2) { + Assert.assertEquals(latLongs2.length, latLongs1.getLatLongCount()); + final Iterator<LatLong> it = latLongs1.iterator(); + for (int i = 0; i < latLongs2.length; i++) { + Assert.assertTrue(it.hasNext()); + Assert.assertEquals(latLongs2[i], latLongs1.getLatLong(i)); + Assert.assertEquals(latLongs2[i], it.next()); + } + Assert.assertFalse(it.hasNext()); + } - @Test - public void testConstructor() { - checkLatLongs(new LatLongs(63.0, 10.3, 63.1, 10.2), new LatLong(63.0, 10.3), new LatLong(63.1, 10.2)); - checkLatLongs(new LatLongs(new LatLong(63.0, 10.3), new LatLong(63.1, 10.2)), new LatLong(63.0, 10.3), new LatLong(63.1, 10.2)); - checkLatLongs(new LatLongs(Arrays.asList(new LatLong(63.1, 10.2), new LatLong(63.1, 10.1))), new LatLong(63.1, 10.2), new LatLong(63.1, 10.1)); - } + @Test + public void testConstructor() { + checkLatLongs(new LatLongs(63.0, 10.3, 63.1, 10.2), new LatLong(63.0, 10.3), + new LatLong(63.1, 10.2)); + checkLatLongs(new LatLongs(new LatLong(63.0, 10.3), new LatLong(63.1, 10.2)), + new LatLong(63.0, 10.3), new LatLong(63.1, 10.2)); + checkLatLongs(new LatLongs(Arrays.asList(new LatLong(63.1, 10.2), new LatLong(63.1, 10.1))), + new LatLong(63.1, 10.2), new LatLong(63.1, 10.1)); + } - @Test - public void testAddLatLong() { - latLongs.addLatLong(new LatLong(63.0, 10.3)); - Assert.assertEquals(1, latLongs.getLatLongCount()); - latLongs.addLatLong(new LatLong(63.1, 10.2)); - Assert.assertEquals(2, latLongs.getLatLongCount()); - } + @Test + public void testAddLatLong() { + latLongs.addLatLong(new LatLong(63.0, 10.3)); + Assert.assertEquals(1, latLongs.getLatLongCount()); + latLongs.addLatLong(new LatLong(63.1, 10.2)); + Assert.assertEquals(2, latLongs.getLatLongCount()); + } - @Test - public void testAddLatLongs() { - final LatLongs lls1 = new LatLongs(); - lls1.addLatLongs(63.0, 10.3, 63.1, 10.2); - checkLatLongs(lls1, new LatLong(63.0, 10.3), new LatLong(63.1, 10.2)); + @Test + public void testAddLatLongs() { + final LatLongs lls1 = new LatLongs(); + lls1.addLatLongs(63.0, 10.3, 63.1, 10.2); + checkLatLongs(lls1, new LatLong(63.0, 10.3), new LatLong(63.1, 10.2)); - final LatLongs lls2 = new LatLongs(); - lls2.addLatLongs(new LatLong(63.0, 10.3), new LatLong(63.1, 10.2)); - checkLatLongs(lls2, new LatLong(63.0, 10.3), new LatLong(63.1, 10.2)); + final LatLongs lls2 = new LatLongs(); + lls2.addLatLongs(new LatLong(63.0, 10.3), new LatLong(63.1, 10.2)); + checkLatLongs(lls2, new LatLong(63.0, 10.3), new LatLong(63.1, 10.2)); - final LatLongs lls3 = new LatLongs(); - lls3.addLatLongs(Arrays.asList(new LatLong(63.1, 10.2), new LatLong(63.1, 10.1))); - checkLatLongs(lls3, new LatLong(63.1, 10.2), new LatLong(63.1, 10.1)); - } + final LatLongs lls3 = new LatLongs(); + lls3.addLatLongs(Arrays.asList(new LatLong(63.1, 10.2), new LatLong(63.1, 10.1))); + checkLatLongs(lls3, new LatLong(63.1, 10.2), new LatLong(63.1, 10.1)); + } } diff --git a/simpleexample/src/test/java/simpleex/json/AbstractJsonTest.java b/simpleexample/src/test/java/simpleex/json/AbstractJsonTest.java index 6b84096..4aaed01 100644 --- a/simpleexample/src/test/java/simpleex/json/AbstractJsonTest.java +++ b/simpleexample/src/test/java/simpleex/json/AbstractJsonTest.java @@ -1,9 +1,7 @@ package simpleex.json; import java.io.IOException; - import org.junit.Assert; - import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonMappingException; @@ -13,37 +11,39 @@ import com.fasterxml.jackson.databind.module.SimpleModule; public abstract class AbstractJsonTest { - private ObjectMapper objectMapper; + private ObjectMapper objectMapper; - public ObjectMapper getObjectMapper() { - return objectMapper; - } + public ObjectMapper getObjectMapper() { + return objectMapper; + } - protected void setUp() { - objectMapper = createObjectMapper(); - } + protected void setUp() { + objectMapper = createObjectMapper(); + } - protected abstract ObjectMapper createObjectMapper(); + protected abstract ObjectMapper createObjectMapper(); - protected <T> SimpleModule createSimpleModule(final Class<T> clazz, final JsonSerializer<T> serializer, final JsonDeserializer<T> deserializer) { - return new SimpleModule() - .addSerializer(clazz, serializer) - .addDeserializer(clazz, deserializer); - } + protected <T> SimpleModule createSimpleModule(final Class<T> clazz, + final JsonSerializer<T> serializer, final JsonDeserializer<T> deserializer) { + return new SimpleModule().addSerializer(clazz, serializer).addDeserializer(clazz, deserializer); + } - protected <T> ObjectMapper createObjectMapper(final Class<T> clazz, final JsonSerializer<T> serializer, final JsonDeserializer<T> deserializer) { - return new ObjectMapper().registerModule(createSimpleModule(clazz, serializer, deserializer)); - } + protected <T> ObjectMapper createObjectMapper(final Class<T> clazz, + final JsonSerializer<T> serializer, final JsonDeserializer<T> deserializer) { + return new ObjectMapper().registerModule(createSimpleModule(clazz, serializer, deserializer)); + } - protected void assertEqualsIgnoreWhitespace(final String expected, final String actual) throws Exception { - Assert.assertEquals(expected, actual.replaceAll("\\s+", "")); - } + protected void assertEqualsIgnoreWhitespace(final String expected, final String actual) + throws Exception { + Assert.assertEquals(expected, actual.replaceAll("\\s+", "")); + } - protected void assertWriteValue(final String expected, final Object value) throws Exception { - assertEqualsIgnoreWhitespace(expected, getObjectMapper().writeValueAsString(value)); - } + protected void assertWriteValue(final String expected, final Object value) throws Exception { + assertEqualsIgnoreWhitespace(expected, getObjectMapper().writeValueAsString(value)); + } - protected <T> T readValue(final String s, final Class<T> clazz) throws IOException, JsonParseException, JsonMappingException { - return getObjectMapper().readValue(s, clazz); - } + protected <T> T readValue(final String s, final Class<T> clazz) + throws IOException, JsonParseException, JsonMappingException { + return getObjectMapper().readValue(s, clazz); + } } diff --git a/simpleexample/src/test/java/simpleex/json/LatLongJsonTest.java b/simpleexample/src/test/java/simpleex/json/LatLongJsonTest.java index 8149251..9edcc39 100644 --- a/simpleexample/src/test/java/simpleex/json/LatLongJsonTest.java +++ b/simpleexample/src/test/java/simpleex/json/LatLongJsonTest.java @@ -3,36 +3,35 @@ package simpleex.json; import org.junit.Assert; import org.junit.Before; import org.junit.Test; - import com.fasterxml.jackson.databind.ObjectMapper; - import simpleex.core.LatLong; public class LatLongJsonTest extends AbstractJsonTest { - @Before - @Override - public void setUp() { - super.setUp(); - } - - @Override - protected ObjectMapper createObjectMapper() { - return createObjectMapper(LatLong.class, new LatLongSerializer(), new LatLongDeserializer()); - } - - @Test - public void testLatLongSerialization() throws Exception { - assertWriteValue("{\"latitude\":63.1,\"longitude\":12.3}", new LatLong(63.1, 12.3)); - } - - @Test - public void testLatLongObjectDeserialization() throws Exception { - Assert.assertEquals(new LatLong(63.1, 12.3), readValue("{\"latitude\":63.1,\"longitude\":12.3}", LatLong.class)); - } - - @Test - public void testLatLongArrayDeserialization() throws Exception { - Assert.assertEquals(new LatLong(63.1, 12.3), readValue("[ 63.1, 12.3 ]", LatLong.class)); - } + @Before + @Override + public void setUp() { + super.setUp(); + } + + @Override + protected ObjectMapper createObjectMapper() { + return createObjectMapper(LatLong.class, new LatLongSerializer(), new LatLongDeserializer()); + } + + @Test + public void testLatLongSerialization() throws Exception { + assertWriteValue("{\"latitude\":63.1,\"longitude\":12.3}", new LatLong(63.1, 12.3)); + } + + @Test + public void testLatLongObjectDeserialization() throws Exception { + Assert.assertEquals(new LatLong(63.1, 12.3), + readValue("{\"latitude\":63.1,\"longitude\":12.3}", LatLong.class)); + } + + @Test + public void testLatLongArrayDeserialization() throws Exception { + Assert.assertEquals(new LatLong(63.1, 12.3), readValue("[ 63.1, 12.3 ]", LatLong.class)); + } } diff --git a/simpleexample/src/test/java/simpleex/json/LatLongsJsonTest.java b/simpleexample/src/test/java/simpleex/json/LatLongsJsonTest.java index 6834bd9..7b097de 100644 --- a/simpleexample/src/test/java/simpleex/json/LatLongsJsonTest.java +++ b/simpleexample/src/test/java/simpleex/json/LatLongsJsonTest.java @@ -3,39 +3,41 @@ package simpleex.json; import org.junit.Assert; import org.junit.Before; import org.junit.Test; - import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.module.SimpleModule; - import simpleex.core.LatLong; import simpleex.core.LatLongs; public class LatLongsJsonTest extends AbstractJsonTest { - @Before - @Override - public void setUp() { - super.setUp(); - } - - @Override - protected ObjectMapper createObjectMapper() { - final SimpleModule module = createSimpleModule(LatLong.class,new LatLongSerializer(), new LatLongDeserializer()); - module.addSerializer(LatLongs.class, new LatLongsSerializer()); - module.addDeserializer(LatLongs.class, new LatLongsDeserializer()); - return new ObjectMapper().registerModule(module); - } - - @Test - public void testLatLongsSerialization() throws Exception { - assertWriteValue("[{\"latitude\":63.1,\"longitude\":12.3},{\"latitude\":63.0,\"longitude\":12.4}]", new LatLongs(new LatLong(63.1, 12.3), new LatLong(63.0, 12.4))); - } - - @Test - public void testLatLongsDeserialization() throws Exception { - final LatLongs latLongs = readValue("[{\"latitude\":63.1,\"longitude\":12.3}, [63.0,12.4]]", LatLongs.class); - Assert.assertEquals(2, latLongs.getLatLongCount()); - Assert.assertEquals(new LatLong(63.1, 12.3), latLongs.getLatLong(0)); - Assert.assertEquals(new LatLong(63.0, 12.4), latLongs.getLatLong(1)); - } + @Before + @Override + public void setUp() { + super.setUp(); + } + + @Override + protected ObjectMapper createObjectMapper() { + final SimpleModule module = + createSimpleModule(LatLong.class, new LatLongSerializer(), new LatLongDeserializer()); + module.addSerializer(LatLongs.class, new LatLongsSerializer()); + module.addDeserializer(LatLongs.class, new LatLongsDeserializer()); + return new ObjectMapper().registerModule(module); + } + + @Test + public void testLatLongsSerialization() throws Exception { + assertWriteValue( + "[{\"latitude\":63.1,\"longitude\":12.3},{\"latitude\":63.0,\"longitude\":12.4}]", + new LatLongs(new LatLong(63.1, 12.3), new LatLong(63.0, 12.4))); + } + + @Test + public void testLatLongsDeserialization() throws Exception { + final LatLongs latLongs = + readValue("[{\"latitude\":63.1,\"longitude\":12.3}, [63.0,12.4]]", LatLongs.class); + Assert.assertEquals(2, latLongs.getLatLongCount()); + Assert.assertEquals(new LatLong(63.1, 12.3), latLongs.getLatLong(0)); + Assert.assertEquals(new LatLong(63.0, 12.4), latLongs.getLatLong(1)); + } } diff --git a/simpleexample/src/test/java/simpleex/ui/FxAppTest.java b/simpleexample/src/test/java/simpleex/ui/FxAppTest.java index bdeea45..1be05ec 100644 --- a/simpleexample/src/test/java/simpleex/ui/FxAppTest.java +++ b/simpleexample/src/test/java/simpleex/ui/FxAppTest.java @@ -3,15 +3,12 @@ package simpleex.ui; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; - import java.util.ArrayList; import java.util.List; - import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.testfx.framework.junit.ApplicationTest; - import fxmapcontrol.Location; import fxmapcontrol.MapBase; import javafx.fxml.FXMLLoader; @@ -25,85 +22,87 @@ import simpleex.core.LatLongs; public class FxAppTest extends ApplicationTest { - @BeforeClass - public static void headless() { - if (Boolean.valueOf(System.getProperty("gitlab-ci", "false"))) { - System.setProperty("prism.verbose", "true"); // optional - System.setProperty("java.awt.headless", "true"); - System.setProperty("testfx.robot", "glass"); - System.setProperty("testfx.headless", "true"); - System.setProperty("glass.platform", "Monocle"); - System.setProperty("monocle.platform", "Headless"); - System.setProperty("prism.order", "sw"); - System.setProperty("prism.text", "t2k"); - System.setProperty("testfx.setup.timeout", "2500"); - } - } + @BeforeClass + public static void headless() { + if (Boolean.valueOf(System.getProperty("gitlab-ci", "false"))) { + System.setProperty("prism.verbose", "true"); // optional + System.setProperty("java.awt.headless", "true"); + System.setProperty("testfx.robot", "glass"); + System.setProperty("testfx.headless", "true"); + System.setProperty("glass.platform", "Monocle"); + System.setProperty("monocle.platform", "Headless"); + System.setProperty("prism.order", "sw"); + System.setProperty("prism.text", "t2k"); + System.setProperty("testfx.setup.timeout", "2500"); + } + } - private FxAppController controller; - private LatLongs latLongs; + private FxAppController controller; + private LatLongs latLongs; - @Override - public void start(final Stage stage) throws Exception { - final FXMLLoader loader = new FXMLLoader(getClass().getResource("FxApp.fxml")); - final Parent root = loader.load(); - this.controller = loader.getController(); - setUpLatLongs(); - final Scene scene = new Scene(root); - stage.setScene(scene); - stage.show(); - } + @Override + public void start(final Stage stage) throws Exception { + final FXMLLoader loader = new FXMLLoader(getClass().getResource("FxApp.fxml")); + final Parent root = loader.load(); + this.controller = loader.getController(); + setUpLatLongs(); + final Scene scene = new Scene(root); + stage.setScene(scene); + stage.show(); + } - private List<LatLong> latLongList; + private List<LatLong> latLongList; - private void setUpLatLongs() { - // test data - latLongList = new ArrayList<>(List.of(new LatLong(63.1, 11.2), new LatLong(63.2, 11.0))); - // "mocked" (faked) LatLongs object with very specific and limited behavior - latLongs = mock(LatLongs.class); - // get nth LatLong object - when(latLongs.getLatLong(anyInt())).then(invocation -> latLongList.get(invocation.getArgument(0))); - // get the number of LatLong objects - when(latLongs.getLatLongCount()).then(invocation -> latLongList.size()); - // iterator for LatLong objects - when(latLongs.iterator()).then(invocation -> latLongList.iterator()); - controller.setLatLongs(latLongs); - } + private void setUpLatLongs() { + // test data + latLongList = new ArrayList<>(List.of(new LatLong(63.1, 11.2), new LatLong(63.2, 11.0))); + // "mocked" (faked) LatLongs object with very specific and limited behavior + latLongs = mock(LatLongs.class); + // get nth LatLong object + when(latLongs.getLatLong(anyInt())) + .then(invocation -> latLongList.get(invocation.getArgument(0))); + // get the number of LatLong objects + when(latLongs.getLatLongCount()).then(invocation -> latLongList.size()); + // iterator for LatLong objects + when(latLongs.iterator()).then(invocation -> latLongList.iterator()); + controller.setLatLongs(latLongs); + } - @Test - public void testController() { - Assert.assertNotNull(this.controller); - } + @Test + public void testController() { + Assert.assertNotNull(this.controller); + } - @Test - public void testLocationListView() { - final ListView<?> locationListView = lookup("#locationListView").query(); - // list contains equals elements in same order - Assert.assertEquals(latLongList, locationListView.getItems()); - // first list element is auto-selected - Assert.assertEquals(0, locationListView.getSelectionModel().getSelectedIndex()); - } + @Test + public void testLocationListView() { + final ListView<?> locationListView = lookup("#locationListView").query(); + // list contains equals elements in same order + Assert.assertEquals(latLongList, locationListView.getItems()); + // first list element is auto-selected + Assert.assertEquals(0, locationListView.getSelectionModel().getSelectedIndex()); + } - @Test - public void testMapView() { - final MapBase mapView = lookup("#mapView").query(); - // center of map view is approx. the first LatLong object - final Location center = mapView.getCenter(); - final double epsilon = 0.000001; // round-off error - Assert.assertEquals(latLongList.get(0).getLatitude(), center.getLatitude(), epsilon); - Assert.assertEquals(latLongList.get(0).getLongitude(), center.getLongitude(), epsilon); - } + @Test + public void testMapView() { + final MapBase mapView = lookup("#mapView").query(); + // center of map view is approx. the first LatLong object + final Location center = mapView.getCenter(); + final double epsilon = 0.000001; // round-off error + Assert.assertEquals(latLongList.get(0).getLatitude(), center.getLatitude(), epsilon); + Assert.assertEquals(latLongList.get(0).getLongitude(), center.getLongitude(), epsilon); + } - @Test - public void testAddLocation() { - // needs map center - final Location center = ((MapBase) lookup("#mapView").query()).getCenter(); - // add behavior for add - final LatLong latLong = new LatLong(center.getLatitude(), center.getLongitude()); - when(latLongs.addLatLong(latLong)).thenReturn(2); // add center + @Test + public void testAddLocation() { + // needs map center + final Location center = ((MapBase) lookup("#mapView").query()).getCenter(); + // add behavior for add + final LatLong latLong = new LatLong(center.getLatitude(), center.getLongitude()); + when(latLongs.addLatLong(latLong)).thenReturn(2); // add center - // make test less sensitive to exact button text - final Button addLocButton = lookup(node -> node instanceof Button && ((Button) node).getText().toLowerCase().startsWith("add loc")).query(); - clickOn(addLocButton); - } + // make test less sensitive to exact button text + final Button addLocButton = lookup(node -> node instanceof Button + && ((Button) node).getText().toLowerCase().startsWith("add loc")).query(); + clickOn(addLocButton); + } } -- GitLab