[jaxx] branch develop updated (e3b9324 -> 1c8d52c)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository jaxx. See http://git.nuiton.org/jaxx.git from e3b9324 [jgitflow-maven-plugin]Updating develop poms back to pre merge state new 1c8d52c fixes #3493: Introduce a new module jaxx-widgets-gis The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 1c8d52cfb2bfe19585ea7d6bfb246ea47a8321f1 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Sep 2 16:15:16 2014 +0200 fixes #3493: Introduce a new module jaxx-widgets-gis Summary of changes: jaxx-demo/pom.xml | 6 + .../demo/component/jaxx/editor/CoordinateDemo.css | 2 +- .../jaxx/editor/CoordinatesEditorDemo.css | 37 ++++ ...omboBoxDemo.jaxx => CoordinatesEditorDemo.jaxx} | 31 +-- .../jaxx/editor/CoordinatesEditorDemoHandler.java | 45 ++++ .../main/java/jaxx/demo/tree/DemoDataProvider.java | 4 +- .../main/resources/i18n/jaxx-demo_en_GB.properties | 9 + .../main/resources/i18n/jaxx-demo_es_ES.properties | 9 + .../main/resources/i18n/jaxx-demo_fr_FR.properties | 7 + LICENSE.txt => jaxx-widgets-gis/LICENSE.txt | 0 README.txt => jaxx-widgets-gis/README.txt | 0 {jaxx-config => jaxx-widgets-gis}/changelog.txt | 0 {jaxx-widgets => jaxx-widgets-gis}/pom.xml | 20 +- .../src/license/THIRD-PARTY.properties | 0 .../nuiton/jaxx/widgets/gis/CoordinateFormat.java | 21 ++ .../nuiton/jaxx/widgets/gis/CoordinateHelper.java | 132 +++++++++++ .../org/nuiton/jaxx/widgets/gis/DdCoordinate.java | 131 +++-------- .../jaxx/widgets/gis/DdCoordinateConverter.java | 129 +++++++++++ .../nuiton/jaxx/widgets}/gis/DmdCoordinate.java | 3 +- .../jaxx/widgets}/gis/DmdCoordinateConverter.java | 2 +- .../nuiton/jaxx/widgets}/gis/DmsCoordinate.java | 3 +- .../jaxx/widgets}/gis/DmsCoordinateConverter.java | 2 +- .../widgets}/gis/MaskFormatterFromConverter.java | 2 +- .../absolute/AbsoluteCoordinateEditorModel.java | 246 +++++++++++++++++++++ .../gis/absolute/AbsoluteDdCoordinateEditor.jaxx | 29 ++- .../AbsoluteDdCoordinateEditorHandler.java | 183 +++++++++++++++ .../absolute/AbsoluteDdCoordinateEditorModel.java | 81 +++++++ .../gis/absolute/AbsoluteDmdCoordinateEditor.jaxx | 26 +-- .../AbsoluteDmdCoordinateEditorHandler.java | 196 ++++++++++++++++ .../absolute/AbsoluteDmdCoordinateEditorModel.java | 64 ++---- .../gis/absolute/AbsoluteDmsCoordinateEditor.jaxx | 27 +-- .../AbsoluteDmsCoordinateEditorHandler.java | 196 ++++++++++++++++ .../absolute/AbsoluteDmsCoordinateEditorModel.java | 60 ++--- .../jaxx/widgets/gis/absolute/CoordinateEditor.css | 12 +- .../widgets/gis/absolute/CoordinatesEditor.css | 187 ++++++++++++++++ .../widgets/gis/absolute/CoordinatesEditor.jaxx | 63 ++++++ .../gis/absolute/CoordinatesEditorHandler.java | 41 ++++ .../gis/absolute/CoordinatesEditorModel.java | 233 +++++++++++++++++++ .../jaxx/widgets/gis/absolute/package-info.java | 8 + .../jaxx/widgets/gis/signed/CoordinateEditor.css | 12 +- .../gis/signed/SignedDdCoordinateEditor.jaxx | 15 +- .../signed/SignedDdCoordinateEditorHandler.java | 64 +++--- .../gis/signed/SignedDdCoordinateEditorModel.java | 33 +-- .../gis/signed/SignedDmdCoordinateEditor.jaxx | 12 +- .../signed/SignedDmdCoordinateEditorHandler.java | 29 +-- .../gis/signed/SignedDmdCoordinateEditorModel.java | 12 +- .../gis/signed/SignedDmsCoordinateEditor.jaxx | 13 +- .../signed/SignedDmsCoordinateEditorHandler.java | 40 ++-- .../gis/signed/SignedDmsCoordinateEditorModel.java | 6 +- .../jaxx/widgets/gis/signed/package-info.java | 8 + .../services/org.nuiton.converter.NuitonConverter | 3 + .../i18n/jaxx-widgets-gis_en_GB.properties | 17 ++ .../i18n/jaxx-widgets-gis_es_ES.properties | 17 ++ .../i18n/jaxx-widgets-gis_fr_FR.properties | 17 ++ .../resources/icons/action-coordinate-reset.png | Bin .../src/site/site.xml | 0 .../widgets/gis/DdCoordinateConverterTest.java | 95 ++++++++ .../nuiton/jaxx/widgets/gis/DdCoordinateTest.java | 108 +++++++++ .../widgets}/gis/DmdCoordinateConverterTest.java | 10 +- .../jaxx/widgets}/gis/DmdCoordinateTest.java | 2 +- .../widgets}/gis/DmsCoordinateConverterTest.java | 2 +- .../jaxx/widgets}/gis/DmsCoordinateTest.java | 4 +- .../gis/signed/SignedDmdCoordinateEditorTest.java | 13 +- .../gis/signed/SignedDmsCoordinateEditorTest.java | 13 +- .../src/test/resources/log4j.properties | 0 pom.xml | 1 + 66 files changed, 2373 insertions(+), 420 deletions(-) create mode 100644 jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/CoordinatesEditorDemo.css copy jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/{BeanComboBoxDemo.jaxx => CoordinatesEditorDemo.jaxx} (66%) create mode 100644 jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/CoordinatesEditorDemoHandler.java copy LICENSE.txt => jaxx-widgets-gis/LICENSE.txt (100%) copy README.txt => jaxx-widgets-gis/README.txt (100%) copy {jaxx-config => jaxx-widgets-gis}/changelog.txt (100%) copy {jaxx-widgets => jaxx-widgets-gis}/pom.xml (90%) copy {jaxx-config => jaxx-widgets-gis}/src/license/THIRD-PARTY.properties (100%) create mode 100644 jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/CoordinateFormat.java create mode 100644 jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/CoordinateHelper.java copy jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinate.java => jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/DdCoordinate.java (64%) create mode 100644 jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/DdCoordinateConverter.java copy {jaxx-widgets/src/main/java/jaxx/runtime/swing/editor => jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets}/gis/DmdCoordinate.java (98%) copy {jaxx-widgets/src/main/java/jaxx/runtime/swing/editor => jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets}/gis/DmdCoordinateConverter.java (99%) copy {jaxx-widgets/src/main/java/jaxx/runtime/swing/editor => jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets}/gis/DmsCoordinate.java (98%) copy {jaxx-widgets/src/main/java/jaxx/runtime/swing/editor => jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets}/gis/DmsCoordinateConverter.java (99%) copy {jaxx-widgets/src/main/java/jaxx/runtime/swing/editor => jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets}/gis/MaskFormatterFromConverter.java (98%) create mode 100644 jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteCoordinateEditorModel.java copy jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditor.jaxx => jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDdCoordinateEditor.jaxx (72%) create mode 100644 jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDdCoordinateEditorHandler.java create mode 100644 jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDdCoordinateEditorModel.java copy jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditor.jaxx => jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmdCoordinateEditor.jaxx (80%) create mode 100644 jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmdCoordinateEditorHandler.java copy jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorModel.java => jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmdCoordinateEditorModel.java (59%) copy jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditor.jaxx => jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmsCoordinateEditor.jaxx (80%) create mode 100644 jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmsCoordinateEditorHandler.java copy jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorModel.java => jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmsCoordinateEditorModel.java (62%) copy jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditor.css => jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/CoordinateEditor.css (94%) create mode 100644 jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/CoordinatesEditor.css create mode 100644 jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/CoordinatesEditor.jaxx create mode 100644 jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/CoordinatesEditorHandler.java create mode 100644 jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/CoordinatesEditorModel.java create mode 100644 jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/package-info.java copy jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditor.css => jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/CoordinateEditor.css (94%) copy jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditor.jaxx => jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDdCoordinateEditor.jaxx (80%) copy jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorHandler.java => jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDdCoordinateEditorHandler.java (80%) copy jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorModel.java => jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDdCoordinateEditorModel.java (76%) copy jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditor.jaxx => jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmdCoordinateEditor.jaxx (88%) copy jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorHandler.java => jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmdCoordinateEditorHandler.java (90%) copy jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorModel.java => jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmdCoordinateEditorModel.java (93%) copy jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditor.jaxx => jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmsCoordinateEditor.jaxx (88%) copy jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorHandler.java => jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmsCoordinateEditorHandler.java (89%) copy jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorModel.java => jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmsCoordinateEditorModel.java (95%) create mode 100644 jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/package-info.java create mode 100644 jaxx-widgets-gis/src/main/resources/META-INF/services/org.nuiton.converter.NuitonConverter create mode 100644 jaxx-widgets-gis/src/main/resources/i18n/jaxx-widgets-gis_en_GB.properties create mode 100644 jaxx-widgets-gis/src/main/resources/i18n/jaxx-widgets-gis_es_ES.properties create mode 100644 jaxx-widgets-gis/src/main/resources/i18n/jaxx-widgets-gis_fr_FR.properties copy jaxx-widgets/src/main/resources/icons/action-combobox-reset.png => jaxx-widgets-gis/src/main/resources/icons/action-coordinate-reset.png (100%) copy {jaxx-widgets => jaxx-widgets-gis}/src/site/site.xml (100%) create mode 100644 jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets/gis/DdCoordinateConverterTest.java create mode 100644 jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets/gis/DdCoordinateTest.java copy {jaxx-widgets/src/test/java/jaxx/runtime/swing/editor => jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets}/gis/DmdCoordinateConverterTest.java (90%) copy {jaxx-widgets/src/test/java/jaxx/runtime/swing/editor => jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets}/gis/DmdCoordinateTest.java (99%) copy {jaxx-widgets/src/test/java/jaxx/runtime/swing/editor => jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets}/gis/DmsCoordinateConverterTest.java (99%) copy {jaxx-widgets/src/test/java/jaxx/runtime/swing/editor => jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets}/gis/DmsCoordinateTest.java (98%) copy jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorTest.java => jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmdCoordinateEditorTest.java (94%) copy jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorTest.java => jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmsCoordinateEditorTest.java (94%) copy {jaxx-widgets => jaxx-widgets-gis}/src/test/resources/log4j.properties (100%) -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository jaxx. See http://git.nuiton.org/jaxx.git commit 1c8d52cfb2bfe19585ea7d6bfb246ea47a8321f1 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Sep 2 16:15:16 2014 +0200 fixes #3493: Introduce a new module jaxx-widgets-gis --- jaxx-demo/pom.xml | 6 + .../demo/component/jaxx/editor/CoordinateDemo.css | 2 +- .../jaxx/editor/CoordinatesEditorDemo.css | 37 +++ .../jaxx/editor/CoordinatesEditorDemo.jaxx | 54 +++ .../jaxx/editor/CoordinatesEditorDemoHandler.java | 45 +++ .../main/java/jaxx/demo/tree/DemoDataProvider.java | 4 +- .../main/resources/i18n/jaxx-demo_en_GB.properties | 9 + .../main/resources/i18n/jaxx-demo_es_ES.properties | 9 + .../main/resources/i18n/jaxx-demo_fr_FR.properties | 7 + jaxx-widgets-gis/LICENSE.txt | 165 +++++++++ jaxx-widgets-gis/README.txt | 2 + jaxx-widgets-gis/changelog.txt | 5 + jaxx-widgets-gis/pom.xml | 205 ++++++++++++ .../src/license/THIRD-PARTY.properties | 20 ++ .../nuiton/jaxx/widgets/gis/CoordinateFormat.java | 21 ++ .../nuiton/jaxx/widgets/gis/CoordinateHelper.java | 132 ++++++++ .../org/nuiton/jaxx/widgets/gis/DdCoordinate.java | 263 +++++++++++++++ .../jaxx/widgets/gis/DdCoordinateConverter.java | 129 +++++++ .../org/nuiton/jaxx/widgets/gis/DmdCoordinate.java | 341 +++++++++++++++++++ .../jaxx/widgets/gis/DmdCoordinateConverter.java | 143 ++++++++ .../org/nuiton/jaxx/widgets/gis/DmsCoordinate.java | 369 +++++++++++++++++++++ .../jaxx/widgets/gis/DmsCoordinateConverter.java | 144 ++++++++ .../widgets/gis/MaskFormatterFromConverter.java | 75 +++++ .../absolute/AbsoluteCoordinateEditorModel.java | 246 ++++++++++++++ .../gis/absolute/AbsoluteDdCoordinateEditor.jaxx | 55 +++ .../AbsoluteDdCoordinateEditorHandler.java | 183 ++++++++++ .../absolute/AbsoluteDdCoordinateEditorModel.java | 81 +++++ .../gis/absolute/AbsoluteDmdCoordinateEditor.jaxx | 56 ++++ .../AbsoluteDmdCoordinateEditorHandler.java | 196 +++++++++++ .../absolute/AbsoluteDmdCoordinateEditorModel.java | 97 ++++++ .../gis/absolute/AbsoluteDmsCoordinateEditor.jaxx | 56 ++++ .../AbsoluteDmsCoordinateEditorHandler.java | 196 +++++++++++ .../absolute/AbsoluteDmsCoordinateEditorModel.java | 96 ++++++ .../jaxx/widgets/gis/absolute/CoordinateEditor.css | 38 +++ .../widgets/gis/absolute/CoordinatesEditor.css | 187 +++++++++++ .../widgets/gis/absolute/CoordinatesEditor.jaxx | 63 ++++ .../gis/absolute/CoordinatesEditorHandler.java | 41 +++ .../gis/absolute/CoordinatesEditorModel.java | 233 +++++++++++++ .../jaxx/widgets/gis/absolute/package-info.java | 8 + .../jaxx/widgets/gis/signed/CoordinateEditor.css | 38 +++ .../gis/signed/SignedDdCoordinateEditor.jaxx | 57 ++++ .../signed/SignedDdCoordinateEditorHandler.java | 298 +++++++++++++++++ .../gis/signed/SignedDdCoordinateEditorModel.java | 108 ++++++ .../gis/signed/SignedDmdCoordinateEditor.jaxx | 58 ++++ .../signed/SignedDmdCoordinateEditorHandler.java | 309 +++++++++++++++++ .../gis/signed/SignedDmdCoordinateEditorModel.java | 125 +++++++ .../gis/signed/SignedDmsCoordinateEditor.jaxx | 58 ++++ .../signed/SignedDmsCoordinateEditorHandler.java | 311 +++++++++++++++++ .../gis/signed/SignedDmsCoordinateEditorModel.java | 124 +++++++ .../jaxx/widgets/gis/signed/package-info.java | 8 + .../services/org.nuiton.converter.NuitonConverter | 3 + .../i18n/jaxx-widgets-gis_en_GB.properties | 17 + .../i18n/jaxx-widgets-gis_es_ES.properties | 17 + .../i18n/jaxx-widgets-gis_fr_FR.properties | 17 + .../resources/icons/action-coordinate-reset.png | Bin 0 -> 396 bytes jaxx-widgets-gis/src/site/site.xml | 43 +++ .../widgets/gis/DdCoordinateConverterTest.java | 95 ++++++ .../nuiton/jaxx/widgets/gis/DdCoordinateTest.java | 108 ++++++ .../widgets/gis/DmdCoordinateConverterTest.java | 102 ++++++ .../nuiton/jaxx/widgets/gis/DmdCoordinateTest.java | 136 ++++++++ .../widgets/gis/DmsCoordinateConverterTest.java | 105 ++++++ .../nuiton/jaxx/widgets/gis/DmsCoordinateTest.java | 131 ++++++++ .../gis/signed/SignedDmdCoordinateEditorTest.java | 213 ++++++++++++ .../gis/signed/SignedDmsCoordinateEditorTest.java | 215 ++++++++++++ .../src/test/resources/log4j.properties | 31 ++ pom.xml | 1 + 66 files changed, 6745 insertions(+), 2 deletions(-) diff --git a/jaxx-demo/pom.xml b/jaxx-demo/pom.xml index cabcaa5..dec9b00 100644 --- a/jaxx-demo/pom.xml +++ b/jaxx-demo/pom.xml @@ -90,6 +90,12 @@ <dependency> <groupId>${project.groupId}</groupId> + <artifactId>jaxx-widgets-gis</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>${project.groupId}</groupId> <artifactId>jaxx-config</artifactId> <version>${project.version}</version> </dependency> diff --git a/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/CoordinateDemo.css b/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/CoordinateDemo.css index 8549a88..b7f5505 100644 --- a/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/CoordinateDemo.css +++ b/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/CoordinateDemo.css @@ -25,7 +25,7 @@ } #latitudeShowReset { - text: "jaxxdemo.numbereditor.showReset"; + text: "jaxxdemo.coordinate.showReset"; selected: true; } diff --git a/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/CoordinatesEditorDemo.css b/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/CoordinatesEditorDemo.css new file mode 100644 index 0000000..a57d84e --- /dev/null +++ b/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/CoordinatesEditorDemo.css @@ -0,0 +1,37 @@ + +#config { + border: {new TitledBorder(t("jaxxdemo.coordinatesEditor.configuration"))}; +} + +#showReset { + text: "jaxxdemo.coordinate.showReset"; + selected: true; +} + +#editorModel { + showResetButton: {showReset.isSelected()}; +} + +#result { + border: {new TitledBorder(t("jaxxdemo.coordinate.result"))}; +} + +#resultFormat { + text: {handler.getFormat(editorModel.getFormat())}; +} + +#resultQuadrant{ + text: {handler.getQuadrant(editorModel.getQuadrant())}; +} + +#resultLatitude{ + text: {handler.getLatitude(editorModel.getLatitude())}; +} + +#resultLongitude{ + text: {handler.getLongitude(editorModel.getLongitude())}; +} + + + + diff --git a/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/CoordinatesEditorDemo.jaxx b/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/CoordinatesEditorDemo.jaxx new file mode 100644 index 0000000..4285ef5 --- /dev/null +++ b/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/CoordinatesEditorDemo.jaxx @@ -0,0 +1,54 @@ +<!-- + #%L + JAXX :: Demo + %% + Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Lesser Public License for more details. + + You should have received a copy of the GNU General Lesser Public + License along with this program. If not, see + <http://www.gnu.org/licenses/lgpl-3.0.html>. + #L% + --> +<jaxx.demo.DemoPanel layout='{new BorderLayout()}'> + + <import> + org.nuiton.jaxx.widgets.gis.absolute.CoordinatesEditor + org.nuiton.jaxx.widgets.gis.absolute.CoordinatesEditorModel + </import> + + <Table insets='0' fill='both' weightx='1' constraints='BorderLayout.NORTH'> + <row> + <cell> + <JPanel id='config' layout='{new GridLayout(1,0)}'> + <JCheckBox id='showReset'/> + </JPanel> + </cell> + </row> + <row> + <cell> + <CoordinatesEditor id='editor'/> + <CoordinatesEditorModel id='editorModel' initializer='editor.getModel()'/> + </cell> + </row> + <row> + <cell> + <JPanel id='result' layout='{new GridLayout(0,1)}'> + <JLabel id='resultFormat'/> + <JLabel id='resultQuadrant'/> + <JLabel id='resultLatitude'/> + <JLabel id='resultLongitude'/> + </JPanel> + </cell> + </row> + </Table> +</jaxx.demo.DemoPanel> diff --git a/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/CoordinatesEditorDemoHandler.java b/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/CoordinatesEditorDemoHandler.java new file mode 100644 index 0000000..e86a193 --- /dev/null +++ b/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/CoordinatesEditorDemoHandler.java @@ -0,0 +1,45 @@ +package jaxx.demo.component.jaxx.editor; + +import jaxx.runtime.spi.UIHandler; +import org.nuiton.jaxx.widgets.gis.CoordinateFormat; +import org.nuiton.jaxx.widgets.gis.absolute.CoordinatesEditorModel; + +import static org.nuiton.i18n.I18n.t; + +/** + * Created on 9/1/14. + * + * @author Tony Chemit - chemit@codelutin.com + * @since XXX + */ +public class CoordinatesEditorDemoHandler implements UIHandler<CoordinatesEditorDemo> { + + @Override + public void beforeInit(CoordinatesEditorDemo ui) { + } + + @Override + public void afterInit(final CoordinatesEditorDemo ui) { + + CoordinatesEditorModel editorModel = ui.getEditorModel(); + editorModel.init(-12f, 42f); + editorModel.setFormat(CoordinateFormat.dd); + + } + + public String getFormat(CoordinateFormat format) { + return t("jaxxdemo.coordinate.result.format", format == null ? null : format.name()); + } + + public String getQuadrant(Integer quadrant) { + return t("jaxxdemo.coordinate.result.quadrant", quadrant); + } + + public String getLatitude(Float latitude) { + return t("jaxxdemo.coordinate.result.latitude", latitude); + } + + public String getLongitude(Float longitude) { + return t("jaxxdemo.coordinate.result.longitude", longitude); + } +} \ No newline at end of file diff --git a/jaxx-demo/src/main/java/jaxx/demo/tree/DemoDataProvider.java b/jaxx-demo/src/main/java/jaxx/demo/tree/DemoDataProvider.java index e3f0fd1..9369d39 100644 --- a/jaxx-demo/src/main/java/jaxx/demo/tree/DemoDataProvider.java +++ b/jaxx-demo/src/main/java/jaxx/demo/tree/DemoDataProvider.java @@ -27,6 +27,7 @@ import jaxx.demo.component.jaxx.StatusMessagePanelDemo; import jaxx.demo.component.jaxx.editor.BeanComboBoxDemo; import jaxx.demo.component.jaxx.editor.ComboEditorDemo; import jaxx.demo.component.jaxx.editor.CoordinateDemo; +import jaxx.demo.component.jaxx.editor.CoordinatesEditorDemo; import jaxx.demo.component.jaxx.editor.DatePickerDemo; import jaxx.demo.component.jaxx.editor.FileEditorDemo; import jaxx.demo.component.jaxx.editor.I18nEditorDemo; @@ -166,7 +167,8 @@ public class DemoDataProvider implements NavDataProvider { BeanComboBoxDemo.class, BeanFilterableComboBoxDemo.class, BeanDoubleListDemo.class, - CoordinateDemo.class + CoordinateDemo.class, + CoordinatesEditorDemo.class ); addMapping(n("jaxxdemo.feature"), diff --git a/jaxx-demo/src/main/resources/i18n/jaxx-demo_en_GB.properties b/jaxx-demo/src/main/resources/i18n/jaxx-demo_en_GB.properties index c270b67..b9c90b4 100644 --- a/jaxx-demo/src/main/resources/i18n/jaxx-demo_en_GB.properties +++ b/jaxx-demo/src/main/resources/i18n/jaxx-demo_en_GB.properties @@ -249,8 +249,17 @@ jaxxdemo.coordinate.model= jaxxdemo.coordinate.model.latitude= jaxxdemo.coordinate.model.longitude= jaxxdemo.coordinate.result= +jaxxdemo.coordinate.result.dd= +jaxxdemo.coordinate.result.dmd= +jaxxdemo.coordinate.result.dms= +jaxxdemo.coordinate.result.format= jaxxdemo.coordinate.result.latitude= +jaxxdemo.coordinate.result.latitude.format= jaxxdemo.coordinate.result.longitude= +jaxxdemo.coordinate.result.longitude.format= +jaxxdemo.coordinate.result.quadrant= +jaxxdemo.coordinate.showReset= +jaxxdemo.coordinatesEditor.configuration= jaxxdemo.datePickerEditor.dateResult=Result display jaxxdemo.datePickerEditor.patternLayout=Date pattern jaxxdemo.datePickerEditor.showPopupButton=Display popup button diff --git a/jaxx-demo/src/main/resources/i18n/jaxx-demo_es_ES.properties b/jaxx-demo/src/main/resources/i18n/jaxx-demo_es_ES.properties index 9e6d171..432e725 100644 --- a/jaxx-demo/src/main/resources/i18n/jaxx-demo_es_ES.properties +++ b/jaxx-demo/src/main/resources/i18n/jaxx-demo_es_ES.properties @@ -250,8 +250,17 @@ jaxxdemo.coordinate.model= jaxxdemo.coordinate.model.latitude= jaxxdemo.coordinate.model.longitude= jaxxdemo.coordinate.result= +jaxxdemo.coordinate.result.dd= +jaxxdemo.coordinate.result.dmd= +jaxxdemo.coordinate.result.dms= +jaxxdemo.coordinate.result.format= jaxxdemo.coordinate.result.latitude= +jaxxdemo.coordinate.result.latitude.format= jaxxdemo.coordinate.result.longitude= +jaxxdemo.coordinate.result.longitude.format= +jaxxdemo.coordinate.result.quadrant= +jaxxdemo.coordinate.showReset= +jaxxdemo.coordinatesEditor.configuration= jaxxdemo.datePickerEditor.dateResult=Affichage du résultat jaxxdemo.datePickerEditor.patternLayout=Pattern de date jaxxdemo.datePickerEditor.showPopupButton=Afficher le boutton pour ouvrir la popup diff --git a/jaxx-demo/src/main/resources/i18n/jaxx-demo_fr_FR.properties b/jaxx-demo/src/main/resources/i18n/jaxx-demo_fr_FR.properties index 142465e..c1c675b 100644 --- a/jaxx-demo/src/main/resources/i18n/jaxx-demo_fr_FR.properties +++ b/jaxx-demo/src/main/resources/i18n/jaxx-demo_fr_FR.properties @@ -246,8 +246,15 @@ jaxxdemo.coordinate.longitudeDd=Longitude (au format DD) jaxxdemo.coordinate.longitudeDmd=Longitude (au format DMD) jaxxdemo.coordinate.longitudeDms=Longitude (au format DMS) jaxxdemo.coordinate.result=Résultat +jaxxdemo.coordinate.result.dd=Coordonnées au format DD %s - %s +jaxxdemo.coordinate.result.dmd=Coordonnées au format DMS %s - %s +jaxxdemo.coordinate.result.dms=Coordonnées au format DMD %s - %s +jaxxdemo.coordinate.result.format=<html>Format <strong>%s</strong> jaxxdemo.coordinate.result.latitude=<html>Latitude <strong>%s</strong> jaxxdemo.coordinate.result.longitude=<html>Longitude <strong>%s</strong> +jaxxdemo.coordinate.result.quadrant=<html>Quadrant <strong>%s</strong> +jaxxdemo.coordinate.showReset=Afficher le boutton de reset +jaxxdemo.coordinatesEditor.configuration=Configuration jaxxdemo.datePickerEditor.dateResult=Affichage du résultat jaxxdemo.datePickerEditor.patternLayout=Pattern de date jaxxdemo.datePickerEditor.showPopupButton=Afficher le boutton pour ouvrir la popup diff --git a/jaxx-widgets-gis/LICENSE.txt b/jaxx-widgets-gis/LICENSE.txt new file mode 100644 index 0000000..cca7fc2 --- /dev/null +++ b/jaxx-widgets-gis/LICENSE.txt @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/jaxx-widgets-gis/README.txt b/jaxx-widgets-gis/README.txt new file mode 100644 index 0000000..d2e50d3 --- /dev/null +++ b/jaxx-widgets-gis/README.txt @@ -0,0 +1,2 @@ +To deploy new version of pom: mvn deploy +To install localy: mvn install diff --git a/jaxx-widgets-gis/changelog.txt b/jaxx-widgets-gis/changelog.txt new file mode 100644 index 0000000..1e285bd --- /dev/null +++ b/jaxx-widgets-gis/changelog.txt @@ -0,0 +1,5 @@ +1.6.0 + * introduce StatusMessageBar and AboutPanel (fork from nuiton-widgets but in JAXX :)) + +1.5 + * 20090404 [chemit] - initial version diff --git a/jaxx-widgets-gis/pom.xml b/jaxx-widgets-gis/pom.xml new file mode 100644 index 0000000..6437bdb --- /dev/null +++ b/jaxx-widgets-gis/pom.xml @@ -0,0 +1,205 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + #%L + JAXX :: Widgets + + $Id$ + $HeadURL$ + %% + Copyright (C) 2008 - 2010 CodeLutin + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Lesser Public License for more details. + + You should have received a copy of the GNU General Lesser Public + License along with this program. If not, see + <http://www.gnu.org/licenses/lgpl-3.0.html>. + #L% + --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.nuiton</groupId> + <artifactId>jaxx</artifactId> + <version>2.12-SNAPSHOT</version> + </parent> + + <groupId>org.nuiton.jaxx</groupId> + <artifactId>jaxx-widgets-gis</artifactId> + + <name>JAXX :: Widgets Gis</name> + <description>Gis widgets wrote with JAXX</description> + + <properties> + <jaxx.addSourcesToClassPath>true</jaxx.addSourcesToClassPath> + <jaxx.autoImportCss>true</jaxx.autoImportCss> + <jaxx.addAutoHandlerUI>true</jaxx.addAutoHandlerUI> + <jaxx.autoRecurseInCss>false</jaxx.autoRecurseInCss> + <!--jaxx.useUIManagerForIcon>true</jaxx.useUIManagerForIcon--> + </properties> + + <dependencies> + + <!-- sibiling dependencies --> + + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>jaxx-runtime</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>jaxx-validator</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>jaxx-widgets</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>org.swinglabs.swingx</groupId> + <artifactId>swingx-common</artifactId> + </dependency> + + <dependency> + <groupId>org.swinglabs.swingx</groupId> + <artifactId>swingx-core</artifactId> + </dependency> + + <dependency> + <groupId>org.swinglabs.swingx</groupId> + <artifactId>swingx-autocomplete</artifactId> + </dependency> + + <dependency> + <groupId>org.nuiton.i18n</groupId> + <artifactId>nuiton-i18n</artifactId> + </dependency> + + <dependency> + <groupId>org.nuiton</groupId> + <artifactId>nuiton-utils</artifactId> + </dependency> + + <dependency> + <groupId>org.nuiton</groupId> + <artifactId>nuiton-decorator</artifactId> + </dependency> + + <dependency> + <groupId>org.nuiton</groupId> + <artifactId>nuiton-converter</artifactId> + </dependency> + + <dependency> + <groupId>com.google.guava</groupId> + <artifactId>guava</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + </dependency> + + <dependency> + <groupId>commons-primitives</groupId> + <artifactId>commons-primitives</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-collections4</artifactId> + </dependency> + + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </dependency> + + <dependency> + <groupId>commons-beanutils</groupId> + <artifactId>commons-beanutils</artifactId> + </dependency> + + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + </dependency> + + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> + + </dependencies> + + <build> + + <resources> + <resource> + <directory>src/main/resources</directory> + <includes> + <include>**/*</include> + </includes> + </resource> + </resources> + + <plugins> + + <plugin> + <groupId>${project.groupId}</groupId> + <artifactId>jaxx-maven-plugin</artifactId> + <version>${project.version}</version> + <executions> + <execution> + <goals> + <goal>generate</goal> + </goals> + </execution> + </executions> + </plugin> + + <plugin> + <groupId>org.nuiton.i18n</groupId> + <artifactId>i18n-maven-plugin</artifactId> + <configuration> + <entries> + <entry> + <basedir>${project.build.directory}/generated-sources/java</basedir> + </entry> + </entries> + </configuration> + <executions> + <execution> + <goals> + <goal>parserJava</goal> + <goal>gen</goal> + </goals> + </execution> + </executions> + </plugin> + + </plugins> + </build> + +</project> diff --git a/jaxx-widgets-gis/src/license/THIRD-PARTY.properties b/jaxx-widgets-gis/src/license/THIRD-PARTY.properties new file mode 100644 index 0000000..81b2769 --- /dev/null +++ b/jaxx-widgets-gis/src/license/THIRD-PARTY.properties @@ -0,0 +1,20 @@ +# Generated by org.codehaus.mojo.license.AddThirdPartyMojo +#------------------------------------------------------------------------------- +# Already used licenses in project : +# - BSD License +# - COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 +# - Common Public License Version 1.0 +# - GNU General Public License - Version 2 with the class path exception +# - Indiana University Extreme! Lab Software License, vesion 1.1.1 +# - Lesser General Public License (LGPL) +# - Lesser General Public License (LGPL) v 3.0 +# - Lesser General Public License (LPGL) +# - Lesser General Public License (LPGL) v 2.1 +# - MIT License +# - The Apache Software License, Version 2.0 +#------------------------------------------------------------------------------- +# Please fill the missing licenses for dependencies : +# +# +#Thu Aug 18 07:10:57 CEST 2011 +commons-primitives--commons-primitives--1.0=The Apache Software License, Version 2.0 diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/CoordinateFormat.java b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/CoordinateFormat.java new file mode 100644 index 0000000..eeca9b3 --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/CoordinateFormat.java @@ -0,0 +1,21 @@ +package org.nuiton.jaxx.widgets.gis; + +/** + * Created on 8/31/14. + * + * @author Tony Chemit - chemit@codelutin.com + */ +public enum CoordinateFormat { + /** + * degre decimal + */ + dd, + /** + * degre minute second + */ + dms, + /** + * degre minute decimal + */ + dmd +} diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/CoordinateHelper.java b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/CoordinateHelper.java new file mode 100644 index 0000000..b95f2d8 --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/CoordinateHelper.java @@ -0,0 +1,132 @@ +/* + * #%L + * ObServe :: Entities + * %% + * Copyright (C) 2010 - 2011 IRD, Codelutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package org.nuiton.jaxx.widgets.gis; + +import java.math.BigDecimal; + +/** + * Helper to deal with coordinates. + * + * @author Tony Chemit - chemit@codelutin.com + */ +public class CoordinateHelper { + + /** + * Calcule le quadrant à partir d'une {@code longitude} et {@code latitude}. + * + * @param longitude la longitude décimale + * @param latitude la latitude décimale + * @return la valeur du quadrant ou {@code null} si l'une des deux + * coordonnées est {@code null}. + * @since 1.2 + */ + public static Integer getQuadrant(Float longitude, Float latitude) { + if (longitude == null || latitude == null) { + return null; + } + int result; + + if (latitude > 0) { + result = longitude > 0 ? 1 : 4; + } else { + result = longitude > 0 ? 2 : 3; + } + return result; + } + + /** + * Calcule la valeur signée de la longitude à partir du {@code quadrant} et + * de la valeur absolue de la {@code longitude}. + * + * @param quadrant la valeur du quandrant (peut être null) + * @param longitude la longitude décimale (peut être null) + * @return la valeur signée de la longitude ou {@code null} si l'une des + * deux données d'entrée est {@code null}. + * @since 1.2 + */ + public static Float getSignedLongitude(Integer quadrant, Float longitude) { + if (longitude == null) { + return null; + } + if (quadrant == null) { + + // cas special ou pas encore de quadrant positionne, on conserve + // juste la valeur de la longitude sans rien faire d'autre + return longitude; + } + int result; + switch (quadrant) { + case 1: + case 2: + result = 1; + break; + default: + result = -1; + } + return result * longitude; + } + + /** + * Calcule la valeur signée de la latitude à partir du {@code quadrant} et + * de la valeur absolue de la {@code latitude}. + * + * @param quadrant la valeur du quandrant (peut être null) + * @param latitude la longitude décimale (peut être null) + * @return la valeur signée de la latitude ou {@code null} si l'une des + * deux données d'entrée est {@code null}. + * @since 1.2 + */ + public static Float getSignedLatitude(Integer quadrant, Float latitude) { + if (latitude == null) { + return null; + } + if (quadrant == null) { + + // cas special ou pas encore de quadrant positionne, on conserve + // juste la valeur de la latitude sans rien faire d'autre + return latitude; + } + int result; + switch (quadrant) { + case 1: + case 4: + result = 1; + break; + default: + result = -1; + } + return result * latitude; + } + + public static Float roundToThreeDecimals(Float aFloat) { + + Float roundFloat; + if (aFloat == null) { + roundFloat = null; + } else { + roundFloat = new BigDecimal(aFloat).setScale(3, BigDecimal.ROUND_HALF_DOWN).floatValue(); + } + return roundFloat; + + } + +} diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/DdCoordinate.java b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/DdCoordinate.java new file mode 100644 index 0000000..b703747 --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/DdCoordinate.java @@ -0,0 +1,263 @@ +package org.nuiton.jaxx.widgets.gis; + +import org.jdesktop.beans.AbstractSerializableBean; + +import java.math.BigDecimal; +import java.util.regex.Pattern; + +/** + * Created on 9/2/14. + * + * @author Tony Chemit - chemit@codelutin.com + * @since XXX + */ +public class DdCoordinate extends AbstractSerializableBean { + + private static final long serialVersionUID = 1L; + + public static final String COORDINATE_STRING_PATTERN = "%s%s.%s"; + + public static final Pattern COORDINATE_PATTERN = Pattern.compile("(.*)\\.(.*)"); + + public static final String PROPERTY_SIGN = "sign"; + + public static final String PROPERTY_DEGREE = "degree"; + + public static final String PROPERTY_DECIMAL = "decimal"; + + protected boolean sign; + + protected Integer degree; + + protected Integer decimal; + + public static DdCoordinate empty() { + DdCoordinate r = new DdCoordinate(); + return r; + } + + /** + * Methode statique de fabrique de position a partir d'un autre {@link DdCoordinate}. + * <p/> + * Note : Si la valeur vaut <code>null</code>, alors on + * reinitialise les composants de la position a <code>null</code> et la + * methode {@link #isNull()} vaudra alors {@code true}. + * + * @param decimal la valeur au format decimal + * @return une nouvelle instance de position convertie + */ + public static DdCoordinate valueOf(DdCoordinate decimal) { + DdCoordinate r = empty(); + if (decimal != null) { + r.setSign(decimal.isSign()); + r.setDegree(decimal.getDegree()); + r.setDecimal(decimal.getDecimal()); + } + return r; + } + + /** + * Methode statique de fabrique de position a partir d'une valeur du format + * decimal. + * <p/> + * Note : Si la valeur (au format decimal) vaut <code>null</code>, alors on + * reinitialise les composants de la position a <code>null</code> et la + * methode {@link #isNull()} vaudra alors {@code true}. + * + * @param decimal la valeur au format decimal + * @return une nouvelle instance de position convertie + */ + public static DdCoordinate valueOf(Float decimal) { + DdCoordinate r = new DdCoordinate(); + r.fromDecimal(decimal); + return r; + } + + /** + * Methode statique de fabrique de position a partir d'une valeur du format + * degre décimale. + * + * @param d la valeur des degres + * @param dc la valeur des décimales de minutes + * @return une nouvelle instance de position convertie + */ + public static DdCoordinate valueOf(boolean sign, + Integer d, + Integer dc) { + DdCoordinate r = new DdCoordinate(); + r.setSign(sign); + r.setDegree(d); + r.setDecimal(dc); + return r; + } + + public boolean isSign() { + return sign; + } + + public Integer getDegree() { + return degree; + } + + public Integer getDecimal() { + return decimal; + } + + public void setSign(boolean sign) { + Object oldValue = isSign(); + this.sign = sign; + firePropertyChange(PROPERTY_SIGN, oldValue, sign); + } + + public void setDegree(Integer degree) { + Object oldValue = getDegree(); + this.degree = degree; + firePropertyChange(PROPERTY_DEGREE, oldValue, degree); + } + + public void setDecimal(Integer decimal) { + Object oldValue = getDecimal(); + this.decimal = decimal; + firePropertyChange(PROPERTY_DECIMAL, oldValue, decimal); + } + + /** + * @return {@code true} si aucune composante n'est renseignée, + * {@code false} autrement. + */ + public boolean isNull() { + return degree == null && decimal == null; + } + + public boolean isDegreeNull() { + return degree == null || degree == 0; + } + + public boolean isDecimalNull() { + return decimal == null || decimal == 0; + } + + /** + * Mets a jour les composants de la position a partir d'une valeur decimal. + * <p/> + * Note : Si la valeur (au format decimal) vaut <code>null</code>, alors on + * reinitialise les composants de la position a <code>null</code> et la + * methode {@link #isNull()} vaudra alors {@code true}. + * + * @param decimalValue la valeur decimale a convertir (qui peut etre nulle). + */ + public void fromDecimal(Float decimalValue) { + Integer d = null; + Integer dc = null; + boolean si = false; + if (decimalValue != null) { + si = decimalValue < 0; + + float absDecimal = Math.abs(decimalValue); + + d = (int) (Math.round(absDecimal + 0.5) - 1); + dc = Math.round(1000 * (absDecimal - d)); + } + + degree = d; + decimal = dc; + sign = si; + + if (decimal != null) { + removeTrailingZero(); + } + } + + public Float toDecimal() { + if (isNull()) { + return null; + } + Integer d = getNotNullDegree(); + Integer dc = getNotNullDecimal(); + Float result = Float.valueOf(d); + result += dc / 1000f; + if (sign) { + result *= -1; + } + result = CoordinateHelper.roundToThreeDecimals(result); + return result; + } + + public void addTrailingZero() { + + if (degree == null) { + degree = 0; + } + if (decimal == null) { + decimal = 0; + } + } + + public void removeTrailingZero() { + if (degree != null && degree == 0) { + degree = null; + } + if (decimal != null && decimal == 0) { + decimal = null; + } + } + + public Integer getSignedDegree() { + Integer result = null; + if (!isDegreeNull()) { + result = degree; + if (isSign()) { + result *= -1; + } + } + return result; + } + + public int getNotNullDegree() { + return isDegreeNull() ? 0 : degree; + } + + public int getNotNullDecimal() { + return isDecimalNull() ? 0 : decimal; + } + + public boolean isLatitudeDegreeValid() { + boolean result = isDegreeValid(false); + return result; + } + + public boolean isLongitudeDegreeValid() { + boolean result = isDegreeValid(true); + return result; + } + + public boolean isDecimalValid() { + boolean result = isDecimalNull() || (0 <= decimal && decimal < 1000); + return result; + } + + @Override + public String toString() { + return "DdCoordinateComponent{" + + "sign=" + sign + + ", degree=" + degree + + ", decimal=" + decimal + + '}'; + } + + protected boolean isDegreeValid(boolean longitude) { + boolean result = true; + if (!isDegreeNull()) { + int bound = longitude ? 180 : 90; + if (bound == degree) { + + // can not have decimal + result = isDecimalNull(); + } else { + result = 0 <= degree && degree < bound; + } + } + return result; + } + +} diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/DdCoordinateConverter.java b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/DdCoordinateConverter.java new file mode 100644 index 0000000..f948687 --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/DdCoordinateConverter.java @@ -0,0 +1,129 @@ +package org.nuiton.jaxx.widgets.gis; + +import org.apache.commons.beanutils.ConversionException; +import org.apache.commons.lang3.StringUtils; +import org.nuiton.converter.NuitonConverter; + +import java.util.regex.Matcher; + +import static org.nuiton.i18n.I18n.t; + +/** + * Created on 9/2/14. + * + * @author Tony Chemit - chemit@codelutin.com + * @since XXX + */ +public class DdCoordinateConverter implements NuitonConverter<DdCoordinate> { + + protected boolean useSign; + + protected boolean forLongitude; + + public void setUseSign(boolean useSign) { + this.useSign = useSign; + } + + public void setForLongitude(boolean forLongitude) { + this.forLongitude = forLongitude; + } + + @Override + public <T> T convert(Class<T> aClass, Object value) { + + if (!isEnabled(aClass)) { + throw new ConversionException( + t("jaxx.error.no.convertor.coordinateDd", value)); + } + + Object result = null; + + if (value == null) { + + if (aClass.equals(String.class)) { + + result = String.format( + DdCoordinate.COORDINATE_STRING_PATTERN, + useSign ? "-" : "", + StringUtils.leftPad("", forLongitude ? 3 : 2, ' '), + StringUtils.leftPad("", 3, ' ')); + } + } else { + + if (aClass.equals(value.getClass())) { + + // same class, no convertion to do + result = value; + } else if (value instanceof String) { + + // String to Value + + Matcher matcher = DdCoordinate.COORDINATE_PATTERN.matcher((String) value); + + if (matcher.matches()) { + + String degresStr = matcher.group(1).replaceAll("\\s", ""); + String decimalesStr = matcher.group(2).replaceAll("\\s", ""); + + Integer degre = degresStr.isEmpty() || "-".equals(degresStr) ? null : Math.abs(Integer.valueOf(degresStr)); + Integer decimal; + if (decimalesStr.isEmpty()) { + decimal = null; + } else { + decimalesStr = StringUtils.rightPad(decimalesStr, 3, '0'); + decimal = Integer.valueOf(decimalesStr); + } + + boolean signed = degresStr.contains("-"); + result = DdCoordinate.valueOf(signed, + degre, + decimal); + } + + } else if (value instanceof DdCoordinate) { + + // Value to String + + DdCoordinate coordinate = (DdCoordinate) value; + + boolean sign = coordinate.isSign(); + String signStr = sign ? "-" : ""; + + Integer degree = coordinate.getDegree(); + String degreeStr = degree == null ? "" : degree.toString(); + + Integer decimal = coordinate.getDecimal(); + + String decimalStr; + if (decimal == null) { + decimalStr = ""; + } else { + + decimalStr = StringUtils.leftPad(decimal.toString(), 3, '0'); + while (decimalStr.endsWith("0")) { + decimalStr = decimalStr.substring(0, decimalStr.length() - 1); + } + } + + result = String.format( + DdCoordinate.COORDINATE_STRING_PATTERN, + signStr, + StringUtils.leftPad(degreeStr, forLongitude ? 3 : 2, ' '), +// decimalStr); + StringUtils.rightPad(decimalStr, 3, ' ')); + } + } + return aClass.cast(result); + } + + protected boolean isEnabled(Class<?> aClass) { + return String.class.isAssignableFrom(aClass) || + DdCoordinate.class.isAssignableFrom(aClass); + } + + @Override + public Class<DdCoordinate> getType() { + return DdCoordinate.class; + } + +} \ No newline at end of file diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/DmdCoordinate.java b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/DmdCoordinate.java new file mode 100644 index 0000000..2f85f63 --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/DmdCoordinate.java @@ -0,0 +1,341 @@ +package org.nuiton.jaxx.widgets.gis; + +/* + * #%L + * JAXX :: Widgets + * %% + * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.jdesktop.beans.AbstractSerializableBean; + +import java.util.regex.Pattern; + +/** + * Geo coordinate in degree decimal, minute format. + * <p/> + * Created on 10/23/13. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 2.6 + */ +public class DmdCoordinate extends AbstractSerializableBean { + + private static final long serialVersionUID = 1L; + + public static final String COORDINATE_STRING_PATTERN = "%s%s°%s'%s"; + + public static final Pattern COORDINATE_PATTERN = + Pattern.compile("(.*)°(.*)'(.*)"); + + public static final String PROPERTY_SIGN = "sign"; + + public static final String PROPERTY_DEGREE = "degree"; + + public static final String PROPERTY_MINUTE = "minute"; + + public static final String PROPERTY_DECIMAL = "decimal"; + + protected boolean sign; + + protected Integer degree; + + protected Integer minute; + + protected Integer decimal; + + public static DmdCoordinate empty() { + DmdCoordinate r = new DmdCoordinate(); + return r; + } + + /** + * Methode statique de fabrique de position a partir d'un autre {@link DmdCoordinate}. + * <p/> + * Note : Si la valeur vaut <code>null</code>, alors on + * reinitialise les composants de la position a <code>null</code> et la + * methode {@link #isNull()} vaudra alors {@code true}. + * + * @param decimal la valeur au format decimal + * @return une nouvelle instance de position convertie + */ + public static DmdCoordinate valueOf(DmdCoordinate decimal) { + DmdCoordinate r = empty(); + if (decimal != null) { + r.setSign(decimal.isSign()); + r.setDegree(decimal.getDegree()); + r.setMinute(decimal.getMinute()); + r.setDecimal(decimal.getDecimal()); + } + return r; + } + + /** + * Methode statique de fabrique de position a partir d'une valeur du format + * decimal. + * <p/> + * Note : Si la valeur (au format decimal) vaut <code>null</code>, alors on + * reinitialise les composants de la position a <code>null</code> et la + * methode {@link #isNull()} vaudra alors {@code true}. + * + * @param decimal la valeur au format decimal + * @return une nouvelle instance de position convertie + */ + public static DmdCoordinate valueOf(Float decimal) { + DmdCoordinate r = new DmdCoordinate(); + r.fromDecimal(decimal); + return r; + } + + /** + * Methode statique de fabrique de position a partir d'une valeur du format + * degre décimale minute. + * + * @param d la valeur des degres + * @param m la valeur des minutes + * @param dc la valeur des décimales de minutes + * @return une nouvelle instance de position convertie + */ + public static DmdCoordinate valueOf(boolean sign, + Integer d, + Integer m, + Integer dc) { + DmdCoordinate r = new DmdCoordinate(); + r.setSign(sign); + r.setDegree(d); + r.setMinute(m); + r.setDecimal(dc); + return r; + } + + public boolean isSign() { + return sign; + } + + public Integer getDegree() { + return degree; + } + + public Integer getMinute() { + return minute; + } + + public Integer getDecimal() { + return decimal; + } + + public void setSign(boolean sign) { + Object oldValue = isSign(); + this.sign = sign; + firePropertyChange(PROPERTY_SIGN, oldValue, sign); + } + + public void setDegree(Integer degree) { + Object oldValue = getDegree(); + this.degree = degree; + firePropertyChange(PROPERTY_DEGREE, oldValue, degree); + } + + public void setMinute(Integer minute) { + Object oldValue = getMinute(); + this.minute = minute; + firePropertyChange(PROPERTY_MINUTE, oldValue, minute); + } + + public void setDecimal(Integer decimal) { + Object oldValue = getDecimal(); + this.decimal = decimal; + firePropertyChange(PROPERTY_DECIMAL, oldValue, decimal); + } + + /** + * @return {@code true} si aucune composante n'est renseignée, + * {@code false} autrement. + */ + public boolean isNull() { + return degree == null && minute == null && decimal == null; + } + + public boolean isDegreeNull() { + return degree == null || degree == 0; + } + + public boolean isMinuteNull() { + return minute == null || minute == 0; + } + + public boolean isDecimalNull() { + return decimal == null || decimal == 0; + } + + /** + * Mets a jour les composants de la position a partir d'une valeur decimal. + * <p/> + * Note : Si la valeur (au format decimal) vaut <code>null</code>, alors on + * reinitialise les composants de la position a <code>null</code> et la + * methode {@link #isNull()} vaudra alors {@code true}. + * + * @param decimalValue la valeur decimale a convertir (qui peut etre nulle). + */ + public void fromDecimal(Float decimalValue) { + Integer d = null; + Integer m = null; + Integer dc = null; + boolean si = false; + if (decimalValue != null) { + si = decimalValue < 0; + + float absDecimal = Math.abs(decimalValue); + + d = (int) (Math.round(absDecimal + 0.5) - 1); + int rest = Math.round(100 * 60.0f * (absDecimal - d)); + if (rest > 0) { + m = rest / 100; + dc = (rest - m * 100); + } + } + + degree = d; + minute = m; + decimal = dc; + sign = si; + + if (decimal != null) { + removeTrailingZero(); + } + } + + public Float toDecimal() { + if (isNull()) { + return null; + } + Integer d = getNotNullDegree(); + Integer m = getNotNullMinute(); + Integer dc = getNotNullDecimal(); + Float result = Float.valueOf(d); + result += (m + (dc / 100f)) / 60.0f; + if (sign) { + result *= -1; + } + result = CoordinateHelper.roundToThreeDecimals(result); + return result; + } + + public void addTrailingZero() { + + if (degree == null) { + degree = 0; + } + if (minute == null) { + minute = 0; + } + if (decimal == null) { + decimal = 0; + } + } + + public void removeTrailingZero() { + if (degree != null && degree == 0) { + degree = null; + } + if (minute != null && minute == 0) { + minute = null; + } + if (decimal != null && decimal == 0) { + decimal = null; + } + } + + public Integer getSignedDegree() { + Integer result = null; + if (!isDegreeNull()) { + result = degree; + if (isSign()) { + result *= -1; + } + } + return result; + } + + public int getNotNullDegree() { + return isDegreeNull() ? 0 : degree; + } + + public int getNotNullMinute() { + return isMinuteNull() ? 0 : minute; + } + + public int getNotNullDecimal() { + return isDecimalNull() ? 0 : decimal; + } + + public boolean isLatitudeDegreeValid() { + boolean result = isDegreeValid(false); + return result; + } + + public boolean isLongitudeDegreeValid() { + boolean result = isDegreeValid(true); + return result; + } + + public boolean isMinuteValid() { + boolean result = true; + if (!isMinuteNull()) { + if (minute == 60) { + + // can not have decimal + result = isDecimalNull(); + } else { + result = 0 <= minute && minute < 60; + } + } + return result; + } + + public boolean isDecimalValid() { + boolean result = isDecimalNull() || (0 <= decimal && decimal < 100); + return result; + } + + @Override + public String toString() { + return "DmdCoordinateComponent{" + + "sign=" + sign + + ", degree=" + degree + + ", minute=" + minute + + ", decimal=" + decimal + + '}'; + } + + protected boolean isDegreeValid(boolean longitude) { + boolean result = true; + if (!isDegreeNull()) { + int bound = longitude ? 180 : 90; + if (bound == degree) { + + // can not have minute nor decimal + result = isMinuteNull() && isDecimalNull(); + } else { + result = 0 <= degree && degree < bound; + } + } + return result; + } + +} diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/DmdCoordinateConverter.java b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/DmdCoordinateConverter.java new file mode 100644 index 0000000..e00d56b --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/DmdCoordinateConverter.java @@ -0,0 +1,143 @@ +package org.nuiton.jaxx.widgets.gis; + +/* + * #%L + * JAXX :: Widgets + * %% + * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.apache.commons.beanutils.ConversionException; +import org.apache.commons.lang3.StringUtils; +import org.nuiton.converter.NuitonConverter; + +import java.util.regex.Matcher; + +import static org.nuiton.i18n.I18n.t; + +/** + * Created on 11/25/13. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 2.6 + */ +public class DmdCoordinateConverter implements NuitonConverter<DmdCoordinate> { + + protected boolean useSign; + + protected boolean forLongitude; + + public void setUseSign(boolean useSign) { + this.useSign = useSign; + } + + public void setForLongitude(boolean forLongitude) { + this.forLongitude = forLongitude; + } + + @Override + public <T> T convert(Class<T> aClass, Object value) { + + if (!isEnabled(aClass)) { + throw new ConversionException( + t("jaxx.error.no.convertor.coordinateDmd", value)); + } + + Object result = null; + + if (value == null) { + + if (aClass.equals(String.class)) { + + result = String.format( + DmdCoordinate.COORDINATE_STRING_PATTERN, + useSign ? "-" : "", + StringUtils.leftPad("", forLongitude ? 3 : 2, ' '), + StringUtils.leftPad("", 2, ' '), + StringUtils.leftPad("", 2, ' ')); + } + } else { + + if (aClass.equals(value.getClass())) { + + // same class, no convertion to do + result = value; + } else if (value instanceof String) { + + // String to Value + + Matcher matcher = DmdCoordinate.COORDINATE_PATTERN.matcher((String) value); + + if (matcher.matches()) { + + String degresStr = matcher.group(1).replaceAll("\\s", ""); + String minutesStr = matcher.group(2).replaceAll("\\s", ""); + String decimalesStr = matcher.group(3).replaceAll("\\s", ""); + + Integer degre = degresStr.isEmpty() || "-".equals(degresStr) ? null : Math.abs(Integer.valueOf(degresStr)); + Integer minutes = minutesStr.isEmpty() ? null : Integer.valueOf(minutesStr); + Integer decimal = decimalesStr.isEmpty() ? null : Integer.valueOf(decimalesStr); + + boolean signed = degresStr.contains("-"); + result = DmdCoordinate.valueOf(signed, + degre, + minutes, + decimal); + } + + } else if (value instanceof DmdCoordinate) { + + // Value to String + + DmdCoordinate coordinate = (DmdCoordinate) value; + + boolean sign = coordinate.isSign(); + String signStr = sign ? "-" : ""; + + Integer degree = coordinate.getDegree(); + String degreeStr = degree == null ? "" : degree.toString(); + + Integer minute = coordinate.getMinute(); + String minuteStr = minute == null ? "" : minute.toString(); + + Integer decimal = coordinate.getDecimal(); + String decimalStr = decimal == null ? "" : decimal.toString(); + + result = String.format( + DmdCoordinate.COORDINATE_STRING_PATTERN, + signStr, + StringUtils.leftPad(degreeStr, forLongitude ? 3 : 2, ' '), + StringUtils.leftPad(minuteStr, 2, ' '), + StringUtils.leftPad(decimalStr, 2, ' ')); + } + } + return aClass.cast(result); + } + + protected boolean isEnabled(Class<?> aClass) { + return String.class.isAssignableFrom(aClass) || + DmdCoordinate.class.isAssignableFrom(aClass); + } + + @Override + public Class<DmdCoordinate> getType() { + return DmdCoordinate.class; + } + +} + diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/DmsCoordinate.java b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/DmsCoordinate.java new file mode 100644 index 0000000..70cbf7b --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/DmsCoordinate.java @@ -0,0 +1,369 @@ +package org.nuiton.jaxx.widgets.gis; + +/* + * #%L + * JAXX :: Widgets + * %% + * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.jdesktop.beans.AbstractSerializableBean; + +import java.util.regex.Pattern; + +/** + * Geo coordinate in degree, minute, second format. + * <p/> + * Created on 10/23/13. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 2.6 + */ +public class DmsCoordinate extends AbstractSerializableBean { + + public static final String COORDINATE_STRING_PATTERN = "%s%s°%s'%s''"; + + public static final Pattern COORDINATE_PATTERN = + Pattern.compile("(.*)°(.*)'(.*)''"); + + private static final long serialVersionUID = 1L; + + public static final String PROPERTY_SIGN = "sign"; + + public static final String PROPERTY_DEGREE = "degree"; + + public static final String PROPERTY_MINUTE = "minute"; + + public static final String PROPERTY_SECOND = "second"; + + protected boolean sign; + + protected Integer degree; + + protected Integer minute; + + protected Integer second; + + public static DmsCoordinate empty() { + DmsCoordinate r = new DmsCoordinate(); + return r; + } + + /** + * Methode statique de fabrique de position a partir d'un autre {@link DmsCoordinate}. + * <p/> + * Note : Si la valeur vaut <code>null</code>, alors on + * reinitialise les composants de la position a <code>null</code> et la + * methode {@link #isNull()} vaudra alors {@code true}. + * + * @param decimal la valeur au format decimal + * @return une nouvelle instance de position convertie + */ + public static DmsCoordinate valueOf(DmsCoordinate decimal) { + DmsCoordinate r = new DmsCoordinate(); + if (decimal != null) { + r.setSign(decimal.isSign()); + r.setDegree(decimal.getDegree()); + r.setMinute(decimal.getMinute()); + r.setSecond(decimal.getSecond()); + } + return r; + } + + /** + * Methode statique de fabrique de position a partir d'une valeur du format + * decimal. + * <p/> + * Note : Si la valeur (au format decimal) vaut <code>null</code>, alors on + * reinitialise les composants de la position a <code>null</code> et la + * methode {@link #isNull()} vaudra alors {@code true}. + * + * @param decimal la valeur au format decimal + * @return une nouvelle instance de position convertie + */ + public static DmsCoordinate valueOf(Float decimal) { + DmsCoordinate r = new DmsCoordinate(); + r.fromDecimal(decimal); + return r; + } + + /** + * Methode statique de fabrique de position a partir d'une valeur du format + * degre-minute-seconde. + * + * @param d la valeur des degres + * @param m la valeur des minutes + * @param s la valeur des secondes + * @return une nouvelle instance de position convertie + */ + public static DmsCoordinate valueOf(boolean sign, Integer d, Integer m, Integer s) { + DmsCoordinate r = new DmsCoordinate(); + r.setSign(sign); + r.setDegree(d); + r.setMinute(m); + r.setSecond(s); + return r; + } + + public boolean isSign() { + return sign; + } + + public Integer getDegree() { + return degree; + } + + public Integer getMinute() { + return minute; + } + + public Integer getSecond() { + return second; + } + + public void setSign(boolean sign) { + Object oldValue = isSign(); + this.sign = sign; + firePropertyChange(PROPERTY_SIGN, oldValue, sign); + } + + public void setDegree(Integer degree) { + Object oldValue = getDegree(); + this.degree = degree; + firePropertyChange(PROPERTY_DEGREE, oldValue, degree); + } + + public void setMinute(Integer minute) { + Object oldValue = getMinute(); + this.minute = minute; + firePropertyChange(PROPERTY_MINUTE, oldValue, minute); + } + + public void setSecond(Integer second) { + Object oldValue = getSecond(); + this.second = second; + firePropertyChange(PROPERTY_SECOND, oldValue, second); + } + + public boolean isDegreeNull() { + return degree == null || degree == 0; + } + + public boolean isMinuteNull() { + return minute == null || minute == 0; + } + + public boolean isSecondNull() { + return second == null || second == 0; + } + + /** + * @return {@code true} si aucune composante n'est renseignée, + * {@code false} autrement. + */ + public boolean isNull() { + return degree == null && minute == null && second == null; + } + + /** + * Mets a jour les composants de la position a partir d'une valeur decimal. + * <p/> + * Note : Si la valeur (au format decimal) vaut <code>null</code>, alors on + * reinitialise les composants de la position a <code>null</code> et la + * methode {@link #isNull()} vaudra alors {@code true}. + * + * @param decimal la valeur decimale a convertir (qui peut etre nulle). + */ + public void fromDecimal(Float decimal) { + Integer d = null; + Integer m = null; + Integer s = null; + boolean si = false; + if (decimal != null) { + si = decimal < 0; + + decimal = Math.abs(decimal); + int remain = 0; + + d = (int) (Math.round(decimal + 0.5) - 1); + m = 0; + s = 0; + decimal = 60.0f * (decimal - d); + if (decimal > 0) { + m = (int) (Math.round(decimal + 0.5) - 1); + decimal = 60 * (decimal - m); + if (decimal > 0) { + s = (int) (Math.round(decimal + 0.5) - 1); + remain = (int) (10 * (decimal - s)); + } + } + if (remain > 9) { + s++; + } + if (s == 60) { + m++; + s = 0; + } + if (m == 60) { + d++; + m = 0; + } + } + + degree = d; + minute = m; + second = s; + sign = si; + + if (decimal != null) { + removeTrailingZero(); + } + } + + public Float toDecimal() { + if (isNull()) { + return null; + } + Integer d = getNotNullDegree(); + Integer m = getNotNullMinute(); + + Integer s = getNotNullSecond(); + + Float result = Float.valueOf(d); + + if (m > 0) { + result += (float) m / 60; + if (s == 0) { + result += 0.5f / 3600; + } + } + if (s > 0) { + result += ((float) s + 0.5f) / 3600; + } + + if (sign) { + result *= -1; + } + result = CoordinateHelper.roundToThreeDecimals(result); + return result; + } + + public DmsCoordinate addTrailingZero() { + if (degree == null) { + degree = 0; + } + if (minute == null) { + minute = 0; + } + if (second == null) { + second = 0; + } + return this; + } + + public DmsCoordinate removeTrailingZero() { + if (degree != null && degree == 0) { + degree = null; + } + if (minute != null && minute == 0) { + minute = null; + } + if (second != null && second == 0) { + second = null; + } + return this; + } + + public Integer getSignedDegree() { + Integer result = null; + if (!isDegreeNull()) { + result = degree; + if (isSign()) { + result *= -1; + } + } + return result; + } + + public int getNotNullDegree() { + return isDegreeNull() ? 0 : degree; + } + + public int getNotNullMinute() { + return isMinuteNull() ? 0 : minute; + } + + + public int getNotNullSecond() { + return isSecondNull() ? 0 : second; + } + + public boolean isLatitudeDegreeValid() { + boolean result = isDegreeValid(false); + return result; + } + + public boolean isLongitudeDegreeValid() { + boolean result = isDegreeValid(true); + return result; + } + + public boolean isMinuteValid() { + boolean result = true; + if (!isMinuteNull()) { + if (60 == minute) { + + // check minute and second are null + result = isSecondNull(); + } else { + result = 0 <= minute && minute < 60; + } + } + return result; + } + + public boolean isSecondValid() { + boolean result = isSecondNull() || (0 <= second && second < 60); + return result; + } + + @Override + public String toString() { + return "DmsCoordinateComponent{" + + "sign=" + sign + + ", degree=" + degree + + ", minute=" + minute + + ", second=" + second + + '}'; + } + + protected boolean isDegreeValid(boolean longitude) { + boolean result = true; + if (!isDegreeNull()) { + int bound = longitude ? 180 : 90; + if (bound == degree) { + + // check minute and second are null + result = isMinuteNull() && isSecondNull(); + } else { + result = degree < bound; + } + } + return result; + } +} diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/DmsCoordinateConverter.java b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/DmsCoordinateConverter.java new file mode 100644 index 0000000..862b024 --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/DmsCoordinateConverter.java @@ -0,0 +1,144 @@ +package org.nuiton.jaxx.widgets.gis; + +/* + * #%L + * JAXX :: Widgets + * %% + * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.apache.commons.beanutils.ConversionException; +import org.apache.commons.lang3.StringUtils; +import org.nuiton.converter.NuitonConverter; + +import java.util.regex.Matcher; + +import static org.nuiton.i18n.I18n.t; + +/** + * Created on 11/25/13. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 2.6 + */ +public class DmsCoordinateConverter implements NuitonConverter<DmsCoordinate> { + + protected boolean useSign; + + protected boolean forLongitude; + + public void setUseSign(boolean useSign) { + this.useSign = useSign; + } + + public void setForLongitude(boolean forLongitude) { + this.forLongitude = forLongitude; + } + + @Override + public <T> T convert(Class<T> aClass, Object value) { + + if (!isEnabled(aClass)) { + throw new ConversionException( + t("jaxx.error.no.convertor.coordinateDms", value)); + } + + Object result = null; + + if (value == null) { + + if (aClass.equals(String.class)) { + + result = String.format( + DmsCoordinate.COORDINATE_STRING_PATTERN, + useSign ? "-" : "", + StringUtils.leftPad("", forLongitude ? 3 : 2, ' '), + StringUtils.leftPad("", 2, ' '), + StringUtils.leftPad("", 2, ' ')); + } + } else { + + if (aClass.equals(value.getClass())) { + + // same class, no convertion to do + result = value; + } else if (value instanceof String) { + + // String to Value + + Matcher matcher = DmsCoordinate.COORDINATE_PATTERN.matcher((String) value); + + if (matcher.matches()) { + + String degresStr = matcher.group(1).replaceAll("\\s", ""); + String minutesStr = matcher.group(2).replaceAll("\\s", ""); + String secondsStr = matcher.group(3).replaceAll("\\s", ""); + + Integer degre = degresStr.isEmpty() || "-".equals(degresStr) ? null : Math.abs(Integer.valueOf(degresStr)); + Integer minutes = minutesStr.isEmpty() ? null : Integer.valueOf(minutesStr); + Integer seconds = secondsStr.isEmpty() ? null : Integer.valueOf(secondsStr); + + boolean signed = degresStr.contains("-"); + result = DmsCoordinate.valueOf(signed, + degre, + minutes, + seconds); + } + + } else if (value instanceof DmsCoordinate) { + + // Value to String + + DmsCoordinate coordinate = (DmsCoordinate) value; + + boolean sign = coordinate.isSign(); + String signStr = sign ? "-" : ""; + + Integer degree = coordinate.getDegree(); + String degreeStr = degree == null ? "" : degree.toString(); + + Integer minute = coordinate.getMinute(); + String minuteStr = minute == null ? "" : minute.toString(); + + Integer second = coordinate.getSecond(); + String secondStr = second == null ? "" : second.toString(); + + result = String.format( + DmsCoordinate.COORDINATE_STRING_PATTERN, + signStr, + StringUtils.leftPad(degreeStr, forLongitude ? 3 : 2, ' '), + StringUtils.leftPad(minuteStr, 2, ' '), + StringUtils.leftPad(secondStr, 2, ' ')); + } + } + return aClass.cast(result); + + } + + protected boolean isEnabled(Class<?> aClass) { + return String.class.isAssignableFrom(aClass) || + DmsCoordinate.class.isAssignableFrom(aClass); + } + + @Override + public Class<DmsCoordinate> getType() { + return DmsCoordinate.class; + } + +} + diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/MaskFormatterFromConverter.java b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/MaskFormatterFromConverter.java new file mode 100644 index 0000000..c9bea2f --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/MaskFormatterFromConverter.java @@ -0,0 +1,75 @@ +package org.nuiton.jaxx.widgets.gis; + +/* + * #%L + * JAXX :: Widgets + * %% + * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.apache.commons.beanutils.Converter; + +import javax.swing.text.MaskFormatter; +import java.text.ParseException; + +/** + * Created on 11/25/13. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 2.6 + */ +public class MaskFormatterFromConverter<O> extends MaskFormatter { + + private static final long serialVersionUID = 1L; + + private final Converter converter; + + private final Class<O> type; + + public static <O> MaskFormatterFromConverter<O> newFormatter(Class<O> type, + String pattern, + Converter converter) throws ParseException { + return new MaskFormatterFromConverter<O>(type, pattern, converter); + } + + protected MaskFormatterFromConverter(Class<O> type, + String pattern, + Converter converter) throws ParseException { + super(pattern); + this.type = type; + this.converter = converter; + } + + @Override + public String valueToString(Object value) throws ParseException { + return (String) converter.convert(String.class, value); + } + + @Override + public Object stringToValue(String value) throws ParseException { + return converter.convert(type, value); + } + + protected Converter getConverter() { + return converter; + } + + protected Class<O> getType() { + return type; + } +} diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteCoordinateEditorModel.java b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteCoordinateEditorModel.java new file mode 100644 index 0000000..abd1613 --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteCoordinateEditorModel.java @@ -0,0 +1,246 @@ +package org.nuiton.jaxx.widgets.gis.absolute; + +import org.jdesktop.beans.AbstractSerializableBean; +import org.nuiton.jaxx.widgets.gis.CoordinateFormat; +import org.nuiton.jaxx.widgets.gis.DdCoordinate; +import org.nuiton.jaxx.widgets.gis.DmdCoordinate; +import org.nuiton.jaxx.widgets.gis.DmsCoordinate; + +/** + * Created on 8/31/14. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.7 + */ +public class AbsoluteCoordinateEditorModel extends AbstractSerializableBean { + + private static final long serialVersionUID = 1L; + + public static final String PROPERTY_DD = "dd"; + + public static final String PROPERTY_DD_DEGREE = "ddDegree"; + + public static final String PROPERTY_DD_DECIMAL = "ddDecimal"; + + public static final String PROPERTY_DMS = "dms"; + + public static final String PROPERTY_DMS_DEGREE = "dmsDegree"; + + public static final String PROPERTY_DMS_MINUTE = "dmsMinute"; + + public static final String PROPERTY_DMS_SECOND = "dmsSecond"; + + public static final String PROPERTY_DMD = "dmd"; + + public static final String PROPERTY_DMD_DEGREE = "dmdDegree"; + + public static final String PROPERTY_DMD_MINUTE = "dmdMinute"; + + public static final String PROPERTY_DMD_DECIMAL = "dmdDecimal"; + + /** + * To edit as dd format. + */ + protected final DdCoordinate dd = DdCoordinate.empty(); + + /** + * To edit as dms format. + */ + protected final DmsCoordinate dms = DmsCoordinate.empty(); + + /** + * To edit as dmd format. + */ + protected final DmdCoordinate dmd = DmdCoordinate.empty(); + + + public Float getValue(CoordinateFormat format) { + + Float result = null; + + switch (format) { + + case dd: + result = dd.toDecimal(); + break; + case dms: + result = dms.toDecimal(); + break; + case dmd: + result = dmd.toDecimal(); + break; + } + return result; + + } + + public Float getValue() { + return dd.toDecimal(); + } + + public void setValue(Float value) { + + setDd(value); + setDms(value); + setDmd(value); + + } + + // --- DD --- // + + public DdCoordinate getDd() { + return dd; + } + + public void setDd(Float decimal) { + DdCoordinate position = DdCoordinate.valueOf(decimal); + setDdSign(false); + setDdDegree(position.getDegree()); + setDdDecimal(position.getDecimal()); + firePropertyChange(PROPERTY_DD, null, getDd()); + } + + public boolean isDdSign() { + return false; + } + + public void setDdSign(boolean sign) { + // + } + + public Integer getDdDegree() { + return dd.getDegree(); + } + + public void setDdDegree(Integer degree) { + Object oldValue = getDdDegree(); + if (degree != null) { + degree = Math.abs(degree); + } + dd.setDegree(degree); + firePropertyChange(PROPERTY_DD_DEGREE, oldValue, degree); + } + + public Integer getDdDecimal() { + return dd.getDecimal(); + } + + public void setDdDecimal(Integer decimal) { + Object oldValue = getDdDecimal(); + if (decimal != null) { + decimal = Math.abs(decimal); + } + dd.setDecimal(decimal); + firePropertyChange(PROPERTY_DD_DECIMAL, oldValue, decimal); + } + + // --- DMS --- // + + public DmsCoordinate getDms() { + return dms; + } + + public void setDms(Float decimal) { + DmsCoordinate position = DmsCoordinate.valueOf(decimal); + setDmsSign(false); + setDmsDegree(position.getDegree()); + setDmsMinute(position.getMinute()); + setDmsSecond(position.getSecond()); + firePropertyChange(PROPERTY_DMS, null, getDms()); + } + + public boolean isDmsSign() { + return false; + } + + public void setDmsSign(boolean sign) { + // + } + + public Integer getDmsDegree() { + return dms.getDegree(); + } + + public void setDmsDegree(Integer degree) { + Object oldValue = getDmsDegree(); + if (degree != null) { + degree = Math.abs(degree); + } + dms.setDegree(degree); + firePropertyChange(PROPERTY_DMS_DEGREE, oldValue, degree); + } + + public Integer getDmsMinute() { + return dms.getMinute(); + } + + public void setDmsMinute(Integer minute) { + Object oldValue = getDmsMinute(); + dms.setMinute(minute); + firePropertyChange(PROPERTY_DMS_MINUTE, oldValue, minute); + } + + public Integer getDmsSecond() { + return dms.getSecond(); + } + + public void setDmsSecond(Integer second) { + Object oldValue = getDmsSecond(); + dms.setSecond(second); + firePropertyChange(PROPERTY_DMS_SECOND, oldValue, second); + } + + // --- DMD --- // + + public DmdCoordinate getDmd() { + return dmd; + } + + public void setDmd(Float decimal) { + DmdCoordinate position = DmdCoordinate.valueOf(decimal); + setDmdSign(false); + setDmdDegree(position.getDegree()); + setDmdMinute(position.getMinute()); + setDmdDecimal(position.getDecimal()); + firePropertyChange(PROPERTY_DMD, null, getDmd()); + } + + public boolean isDmdSign() { + return false; + } + + public void setDmdSign(boolean sign) { + // + } + + public Integer getDmdDegree() { + return dmd.getDegree(); + } + + public void setDmdDegree(Integer degree) { + Object oldValue = getDmdDegree(); + dmd.setDegree(degree); + firePropertyChange(PROPERTY_DMD_DEGREE, oldValue, degree); + } + + public Integer getDmdMinute() { + return dmd.getMinute(); + } + + public void setDmdMinute(Integer minute) { + Object oldValue = getDmdMinute(); + dmd.setMinute(minute); + firePropertyChange(PROPERTY_DMD_MINUTE, oldValue, minute); + } + + public Integer getDmdDecimal() { + return dmd.getDecimal(); + } + + public void setDmdDecimal(Integer decimal) { + Object oldValue = getDmdDecimal(); + dmd.setDecimal(decimal); + firePropertyChange(PROPERTY_DMD_DECIMAL, oldValue, decimal); + } + +} diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDdCoordinateEditor.jaxx b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDdCoordinateEditor.jaxx new file mode 100644 index 0000000..c37b3ed --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDdCoordinateEditor.jaxx @@ -0,0 +1,55 @@ +<!-- + #%L + JAXX :: Widgets + %% + Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Lesser Public License for more details. + + You should have received a copy of the GNU General Lesser Public + License along with this program. If not, see + <http://www.gnu.org/licenses/lgpl-3.0.html>. + #L% + --> +<JPanel id='editorPanel' layout='{new BorderLayout()}' onFocusGained='editor.requestFocus()'> + <import> + org.nuiton.jaxx.widgets.gis.DdCoordinate + + java.io.Serializable + java.awt.BorderLayout + javax.swing.JFormattedTextField + </import> + + <style source="CoordinateEditor.css"/> + + <!-- show reset property --> + <Boolean id='showReset' javaBean='false'/> + + <!-- show reset tip --> + <String id='showResetTip' javaBean=''/> + + <!-- model --> + <AbsoluteDdCoordinateEditorModel id='model'/> + + <script><![CDATA[ +public void init(boolean longitudeEditor) { handler.init(longitudeEditor); } +public void setBean(Serializable bean) { model.setBean(bean); } +public void setPropertyDegree(String property ) { model.setPropertyDegree(property); } +public void setPropertyDecimal(String property ) { model.setPropertyDecimal(property); } +public void setValue(DdCoordinate value) { handler.setValue(value, true); } +]]> + </script> + + <JToolBar id='toolbarLeft' constraints='BorderLayout.WEST'> + <JButton id='resetButton' onActionPerformed='handler.resetEditor()'/> + </JToolBar> + <JFormattedTextField id='editor' constraints='BorderLayout.CENTER'/> +</JPanel> diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDdCoordinateEditorHandler.java b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDdCoordinateEditorHandler.java new file mode 100644 index 0000000..80a4fb1 --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDdCoordinateEditorHandler.java @@ -0,0 +1,183 @@ +package org.nuiton.jaxx.widgets.gis.absolute; + +import com.google.common.base.Preconditions; +import jaxx.runtime.spi.UIHandler; +import jaxx.runtime.swing.editor.bean.BeanUIUtil; +import org.nuiton.jaxx.widgets.gis.DdCoordinate; +import org.nuiton.jaxx.widgets.gis.DdCoordinateConverter; +import org.nuiton.jaxx.widgets.gis.MaskFormatterFromConverter; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.JFormattedTextField; +import javax.swing.text.DefaultFormatterFactory; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.lang.reflect.Method; +import java.text.ParseException; + +/** + * Created on 9/2/14. + * + * @author Tony Chemit - chemit@codelutin.com + * @since XXX + */ +public class AbsoluteDdCoordinateEditorHandler implements UIHandler<AbsoluteDdCoordinateEditor> { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(AbsoluteDdCoordinateEditorHandler.class); + + private AbsoluteDdCoordinateEditor ui; + + protected Method degreeMutator; + + protected Method decimalMutator; + + protected boolean valueIsAdjusting; + + protected boolean valueModelIsAdjusting; + + protected DdCoordinateConverter unsignedConverter; + + protected DefaultFormatterFactory formatterFactory; + + @Override + public void beforeInit(AbsoluteDdCoordinateEditor ui) { + this.ui = ui; + // can't use the one from ConverterUtil since we deal with some internal states + this.unsignedConverter = new DdCoordinateConverter(); + } + + @Override + public void afterInit(AbsoluteDdCoordinateEditor ui) { + // nothing special to do here + } + + public void init(boolean longitudeEditor) { + + final AbsoluteDdCoordinateEditorModel model = ui.getModel(); + + Preconditions.checkNotNull(model.getBean(), "could not find bean in " + ui); + Preconditions.checkNotNull(model.getPropertyDegree(), "could not find propertyDegree in " + ui); + Preconditions.checkNotNull(model.getPropertyDecimal(), "could not find propertyDecimal in " + ui); + + Object bean = model.getBean(); + + degreeMutator = BeanUIUtil.getMutator(bean, model.getPropertyDegree()); + Preconditions.checkNotNull(degreeMutator, "could not find mutator for " + model.getPropertyDegree()); + + decimalMutator = BeanUIUtil.getMutator(bean, model.getPropertyDecimal()); + Preconditions.checkNotNull(decimalMutator, "could not find mutator for " + model.getPropertyDecimal()); + + unsignedConverter.setForLongitude(longitudeEditor); + + { + // prepare unsigned formatter factory + String pattern = getMaskFormatterPattern(longitudeEditor); + MaskFormatterFromConverter<DdCoordinate> maskFormatter; + try { + maskFormatter = MaskFormatterFromConverter.newFormatter( + DdCoordinate.class, + pattern, unsignedConverter); + maskFormatter.setValidCharacters(" 01234567890"); + maskFormatter.setCommitsOnValidEdit(true); + formatterFactory = new DefaultFormatterFactory(maskFormatter); + } catch (ParseException e) { + // can't happen here + throw new RuntimeException(e); + } + } + + JFormattedTextField editor = ui.getEditor(); + editor.setFormatterFactory(formatterFactory); + editor.setFocusLostBehavior(JFormattedTextField.COMMIT); + + // When editor changes his value, propagate it to model + editor.addPropertyChangeListener("value", new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + DdCoordinate newValue = (DdCoordinate) evt.getNewValue(); + if (log.isDebugEnabled()) { + log.debug("Value has changed: " + newValue); + } + model.setValue(newValue); + } + }); + + // When model degree changed, let's push it back in bean + model.addPropertyChangeListener( + AbsoluteDdCoordinateEditorModel.PROPERTY_DEGREE, + new ModelPropertyChangeListener(model, degreeMutator)); + + // When model decimal changed, let's push it back in bean + model.addPropertyChangeListener( + AbsoluteDdCoordinateEditorModel.PROPERTY_DECIMAL, + new ModelPropertyChangeListener(model, decimalMutator)); + } + + public void setValue(DdCoordinate value, boolean pushToModel) { + + if (valueModelIsAdjusting) { + // avoid re-entrant code + return; + } + + valueIsAdjusting = !pushToModel; + + try { + ui.getEditor().setValue(value); + } finally { + valueIsAdjusting = false; + } + } + + public void resetEditor() { + // set null value to model + setValue(null, true); + + // use back unsigned format + ui.getEditor().setFormatterFactory(formatterFactory); + } + + protected String getMaskFormatterPattern(boolean longitudeEditor) { + String pattern = "**.***"; + if (longitudeEditor) { + // add one more degre + pattern = "*" + pattern; + } + return pattern; + } + + private class ModelPropertyChangeListener implements PropertyChangeListener { + + private final AbsoluteDdCoordinateEditorModel model; + + private final Method mutator; + + private ModelPropertyChangeListener(AbsoluteDdCoordinateEditorModel model, Method mutator) { + this.model = model; + this.mutator = mutator; + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (!valueIsAdjusting) { + Object newValue = evt.getNewValue(); + + try { + + valueModelIsAdjusting = true; + try { + mutator.invoke(model.getBean(), newValue); + } finally { + valueModelIsAdjusting = false; + } + + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } + } +} \ No newline at end of file diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDdCoordinateEditorModel.java b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDdCoordinateEditorModel.java new file mode 100644 index 0000000..fe157e8 --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDdCoordinateEditorModel.java @@ -0,0 +1,81 @@ +package org.nuiton.jaxx.widgets.gis.absolute; + +import org.nuiton.jaxx.widgets.gis.DdCoordinate; + +import java.io.Serializable; + +/** + * Created on 9/2/14. + * + * @author Tony Chemit - chemit@codelutin.com + * @since XXX + */ +public class AbsoluteDdCoordinateEditorModel extends DdCoordinate { + + public static final String PROPERTY_BEAN = "bean"; + + public static final String PROPERTY_PROPERTY_DEGREE = "propertyDegree"; + + public static final String PROPERTY_PROPERTY_DECIMAL = "propertyDecimal"; + + private static final long serialVersionUID = 1L; + + /** Bean where to push data. */ + protected Serializable bean; + + /** Name of the property of the bean to fire the change of the {@link #degree}. */ + protected String propertyDegree; + + /** Name of the property of the bean to fire the change of the {@link #decimal}. */ + protected String propertyDecimal; + + public Serializable getBean() { + return bean; + } + + public void setBean(Serializable bean) { + Object oldValue = getBean(); + this.bean = bean; + firePropertyChange(PROPERTY_BEAN, oldValue, bean); + } + + public String getPropertyDegree() { + return propertyDegree; + } + + public void setPropertyDegree(String propertyDegree) { + Object oldValue = getPropertyDegree(); + this.propertyDegree = propertyDegree; + firePropertyChange(PROPERTY_PROPERTY_DEGREE, oldValue, propertyDegree); + } + + public String getPropertyDecimal() { + return propertyDecimal; + } + + public void setPropertyDecimal(String propertyDecimal) { + Object oldValue = getPropertyDecimal(); + this.propertyDecimal = propertyDecimal; + firePropertyChange(PROPERTY_PROPERTY_DECIMAL, oldValue, propertyDecimal); + } + + public void setValue(DdCoordinate value) { + setDegree(value == null ? null : value.getDegree()); + setDecimal(value == null ? null : value.getDecimal()); + } + + public String getStringPattern() { + String pattern = COORDINATE_STRING_PATTERN; + return pattern; + } + + @Override + public boolean isSign() { + return false; + } + + @Override + public void setSign(boolean sign) { + // never use it + } +} diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmdCoordinateEditor.jaxx b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmdCoordinateEditor.jaxx new file mode 100644 index 0000000..1a0396a --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmdCoordinateEditor.jaxx @@ -0,0 +1,56 @@ +<!-- + #%L + JAXX :: Widgets + %% + Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Lesser Public License for more details. + + You should have received a copy of the GNU General Lesser Public + License along with this program. If not, see + <http://www.gnu.org/licenses/lgpl-3.0.html>. + #L% + --> +<JPanel id='editorPanel' layout='{new BorderLayout()}' onFocusGained='editor.requestFocus()'> + <import> + org.nuiton.jaxx.widgets.gis.DmdCoordinate + + java.io.Serializable + java.awt.BorderLayout + javax.swing.JFormattedTextField + </import> + + <style source="CoordinateEditor.css"/> + + <!-- show reset property --> + <Boolean id='showReset' javaBean='false'/> + + <!-- show reset tip --> + <String id='showResetTip' javaBean=''/> + + <!-- model --> + <AbsoluteDmdCoordinateEditorModel id='model'/> + + <script><![CDATA[ +public void init(boolean longitudeEditor) { handler.init(longitudeEditor); } +public void setBean(Serializable bean) { model.setBean(bean); } +public void setPropertyDegree(String property ) { model.setPropertyDegree(property); } +public void setPropertyMinute(String property ) { model.setPropertyMinute(property); } +public void setPropertyDecimal(String property ) { model.setPropertyDecimal(property); } +public void setValue(DmdCoordinate value) { handler.setValue(value, true); } +]]> + </script> + + <JToolBar id='toolbarLeft' constraints='BorderLayout.WEST'> + <JButton id='resetButton' onActionPerformed='handler.resetEditor()'/> + </JToolBar> + <JFormattedTextField id='editor' constraints='BorderLayout.CENTER'/> +</JPanel> diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmdCoordinateEditorHandler.java b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmdCoordinateEditorHandler.java new file mode 100644 index 0000000..284ba76 --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmdCoordinateEditorHandler.java @@ -0,0 +1,196 @@ +package org.nuiton.jaxx.widgets.gis.absolute; + +import com.google.common.base.Preconditions; +import jaxx.runtime.spi.UIHandler; +import jaxx.runtime.swing.editor.bean.BeanUIUtil; +import org.nuiton.jaxx.widgets.gis.DmdCoordinate; +import org.nuiton.jaxx.widgets.gis.DmdCoordinateConverter; +import org.nuiton.jaxx.widgets.gis.MaskFormatterFromConverter; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.JFormattedTextField; +import javax.swing.text.DefaultFormatterFactory; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.lang.reflect.Method; +import java.text.ParseException; + +/** + * Created on 9/2/14. + * + * @author Tony Chemit - chemit@codelutin.com + * @since XXX + */ +public class AbsoluteDmdCoordinateEditorHandler implements UIHandler<AbsoluteDmdCoordinateEditor> { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(AbsoluteDmdCoordinateEditorHandler.class); + + private AbsoluteDmdCoordinateEditor ui; + + protected Method signMutator; + + protected Method degreeMutator; + + protected Method minuteMutator; + + protected Method decimalMutator; + + protected boolean valueIsAdjusting; + + protected boolean valueModelIsAdjusting; + + protected DmdCoordinateConverter unsignedConverter; + + protected DefaultFormatterFactory formatterFactory; + + @Override + public void beforeInit(AbsoluteDmdCoordinateEditor ui) { + this.ui = ui; + // can't use the one from ConverterUtil since we deal with some internal states + this.unsignedConverter = new DmdCoordinateConverter(); + } + + @Override + public void afterInit(AbsoluteDmdCoordinateEditor ui) { + // nothing special to do here + } + + public void init(boolean longitudeEditor) { + + final AbsoluteDmdCoordinateEditorModel model = ui.getModel(); + + Preconditions.checkNotNull(model.getBean(), "could not find bean in " + ui); + Preconditions.checkNotNull(model.getPropertyDegree(), "could not find propertyDegree in " + ui); + Preconditions.checkNotNull(model.getPropertyMinute(), "could not find propertyMinute in " + ui); + Preconditions.checkNotNull(model.getPropertyDecimal(), "could not find propertyDecimal in " + ui); + + Object bean = model.getBean(); + + degreeMutator = BeanUIUtil.getMutator(bean, model.getPropertyDegree()); + Preconditions.checkNotNull(degreeMutator, "could not find mutator for " + model.getPropertyDegree()); + + minuteMutator = BeanUIUtil.getMutator(bean, model.getPropertyMinute()); + Preconditions.checkNotNull(minuteMutator, "could not find mutator for " + model.getPropertyMinute()); + + decimalMutator = BeanUIUtil.getMutator(bean, model.getPropertyDecimal()); + Preconditions.checkNotNull(decimalMutator, "could not find mutator for " + model.getPropertyDecimal()); + + unsignedConverter.setForLongitude(longitudeEditor); + + { + // prepare unsigned formatter factory + String pattern = getMaskFormatterPattern(longitudeEditor); + MaskFormatterFromConverter<DmdCoordinate> maskFormatter; + try { + maskFormatter = MaskFormatterFromConverter.newFormatter( + DmdCoordinate.class, + pattern, unsignedConverter); + maskFormatter.setValidCharacters(" 01234567890"); + maskFormatter.setCommitsOnValidEdit(true); + formatterFactory = new DefaultFormatterFactory(maskFormatter); + } catch (ParseException e) { + // can't happen here + throw new RuntimeException(e); + } + } + + JFormattedTextField editor = ui.getEditor(); + editor.setFormatterFactory(formatterFactory); + editor.setFocusLostBehavior(JFormattedTextField.COMMIT); + + // When editor changes his value, propagate it to model + editor.addPropertyChangeListener("value", new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + DmdCoordinate newValue = (DmdCoordinate) evt.getNewValue(); + if (log.isDebugEnabled()) { + log.debug("Value has changed: " + newValue); + } + model.setValue(newValue); + } + }); + + // When model degre changed, let's push it back in bean + model.addPropertyChangeListener( + AbsoluteDmdCoordinateEditorModel.PROPERTY_DEGREE, + new ModelPropertyChangeListener(model, degreeMutator)); + + // When model minute changed, let's push it back in bean + model.addPropertyChangeListener( + AbsoluteDmdCoordinateEditorModel.PROPERTY_MINUTE, + new ModelPropertyChangeListener(model, minuteMutator)); + + // When model decimal changed, let's push it back in bean + model.addPropertyChangeListener( + AbsoluteDmdCoordinateEditorModel.PROPERTY_DECIMAL, + new ModelPropertyChangeListener(model, decimalMutator)); + } + + public void setValue(DmdCoordinate value, boolean pushToModel) { + + if (valueModelIsAdjusting) { + // avoid re-entrant code + return; + } + + valueIsAdjusting = !pushToModel; + + try { + ui.getEditor().setValue(value); + } finally { + valueIsAdjusting = false; + } + } + + public void resetEditor() { + // set null value to model + setValue(null, true); + + // use back unsigned format + ui.getEditor().setFormatterFactory(formatterFactory); + } + + protected String getMaskFormatterPattern(boolean longitudeEditor) { + String pattern = "**°**''**"; + if (longitudeEditor) { + // add one more degre + pattern = "*" + pattern; + } + return pattern; + } + + private class ModelPropertyChangeListener implements PropertyChangeListener { + + private final AbsoluteDmdCoordinateEditorModel model; + + private final Method mutator; + + private ModelPropertyChangeListener(AbsoluteDmdCoordinateEditorModel model, Method mutator) { + this.model = model; + this.mutator = mutator; + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (!valueIsAdjusting) { + Object newValue = evt.getNewValue(); + + try { + + valueModelIsAdjusting = true; + try { + mutator.invoke(model.getBean(), newValue); + } finally { + valueModelIsAdjusting = false; + } + + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } + } +} \ No newline at end of file diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmdCoordinateEditorModel.java b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmdCoordinateEditorModel.java new file mode 100644 index 0000000..1ebcaba --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmdCoordinateEditorModel.java @@ -0,0 +1,97 @@ +package org.nuiton.jaxx.widgets.gis.absolute; + +import org.nuiton.jaxx.widgets.gis.DmdCoordinate; + +import java.io.Serializable; + +/** + * Created on 9/2/14. + * + * @author Tony Chemit - chemit@codelutin.com + * @since XXX + */ +public class AbsoluteDmdCoordinateEditorModel extends DmdCoordinate { + + public static final String PROPERTY_BEAN = "bean"; + + public static final String PROPERTY_PROPERTY_DEGREE = "propertyDegree"; + + public static final String PROPERTY_PROPERTY_MINUTE = "propertyMinute"; + + public static final String PROPERTY_PROPERTY_DECIMAL = "propertyDecimal"; + + private static final long serialVersionUID = 1L; + + /** Bean where to push data. */ + protected Serializable bean; + + /** Name of the property of the bean to fire the change of the {@link #degree}. */ + protected String propertyDegree; + + /** Name of the property of the bean to fire the change of the {@link #minute}. */ + protected String propertyMinute; + + /** Name of the property of the bean to fire the change of the {@link #decimal}. */ + protected String propertyDecimal; + + public Serializable getBean() { + return bean; + } + + public void setBean(Serializable bean) { + Object oldValue = getBean(); + this.bean = bean; + firePropertyChange(PROPERTY_BEAN, oldValue, bean); + } + + public String getPropertyDegree() { + return propertyDegree; + } + + public void setPropertyDegree(String propertyDegree) { + Object oldValue = getPropertyDegree(); + this.propertyDegree = propertyDegree; + firePropertyChange(PROPERTY_PROPERTY_DEGREE, oldValue, propertyDegree); + } + + public String getPropertyMinute() { + return propertyMinute; + } + + public void setPropertyMinute(String propertyMinute) { + Object oldValue = getPropertyMinute(); + this.propertyMinute = propertyMinute; + firePropertyChange(PROPERTY_PROPERTY_MINUTE, oldValue, propertyMinute); + } + + public String getPropertyDecimal() { + return propertyDecimal; + } + + public void setPropertyDecimal(String propertyDecimal) { + Object oldValue = getPropertyDecimal(); + this.propertyDecimal = propertyDecimal; + firePropertyChange(PROPERTY_PROPERTY_DECIMAL, oldValue, propertyDecimal); + } + + public void setValue(DmdCoordinate value) { + setDegree(value == null ? null : value.getDegree()); + setMinute(value == null ? null : value.getMinute()); + setDecimal(value == null ? null : value.getDecimal()); + } + + public String getStringPattern() { + String pattern = COORDINATE_STRING_PATTERN; + return pattern; + } + + @Override + public boolean isSign() { + return false; + } + + @Override + public void setSign(boolean sign) { + // never use it + } +} diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmsCoordinateEditor.jaxx b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmsCoordinateEditor.jaxx new file mode 100644 index 0000000..b502b1c --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmsCoordinateEditor.jaxx @@ -0,0 +1,56 @@ +<!-- + #%L + JAXX :: Widgets + %% + Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Lesser Public License for more details. + + You should have received a copy of the GNU General Lesser Public + License along with this program. If not, see + <http://www.gnu.org/licenses/lgpl-3.0.html>. + #L% + --> +<JPanel id='editorPanel' layout='{new BorderLayout()}' onFocusGained='editor.requestFocus()'> + <import> + org.nuiton.jaxx.widgets.gis.DmsCoordinate + + java.io.Serializable + java.awt.BorderLayout + javax.swing.JFormattedTextField + </import> + + <style source="CoordinateEditor.css"/> + + <!-- show reset property --> + <Boolean id='showReset' javaBean='false'/> + + <!-- show reset tip --> + <String id='showResetTip' javaBean=''/> + + <!-- model --> + <AbsoluteDmsCoordinateEditorModel id='model'/> + + <script><![CDATA[ +public void init(boolean longitudeEditor) { handler.init(longitudeEditor); } +public void setBean(Serializable bean) { model.setBean(bean); } +public void setPropertyDegree(String property ) { model.setPropertyDegree(property); } +public void setPropertyMinute(String property ) { model.setPropertyMinute(property); } +public void setPropertySecond(String property ) { model.setPropertySecond(property); } +public void setValue(DmsCoordinate value) { handler.setValue(value, true); } +]]> + </script> + + <JToolBar id='toolbarLeft' constraints='BorderLayout.WEST'> + <JButton id='resetButton' onActionPerformed='handler.resetEditor()'/> + </JToolBar> + <JFormattedTextField id='editor' constraints='BorderLayout.CENTER'/> +</JPanel> diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmsCoordinateEditorHandler.java b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmsCoordinateEditorHandler.java new file mode 100644 index 0000000..2145c9e --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmsCoordinateEditorHandler.java @@ -0,0 +1,196 @@ +package org.nuiton.jaxx.widgets.gis.absolute; + +import com.google.common.base.Preconditions; +import jaxx.runtime.spi.UIHandler; +import jaxx.runtime.swing.editor.bean.BeanUIUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.jaxx.widgets.gis.DmsCoordinate; +import org.nuiton.jaxx.widgets.gis.DmsCoordinateConverter; +import org.nuiton.jaxx.widgets.gis.MaskFormatterFromConverter; + +import javax.swing.JFormattedTextField; +import javax.swing.text.DefaultFormatterFactory; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.lang.reflect.Method; +import java.text.ParseException; + +/** + * Created on 9/2/14. + * + * @author Tony Chemit - chemit@codelutin.com + * @since XXX + */ +public class AbsoluteDmsCoordinateEditorHandler implements UIHandler<AbsoluteDmsCoordinateEditor> { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(AbsoluteDmsCoordinateEditorHandler.class); + + protected AbsoluteDmsCoordinateEditor ui; + + protected Method degreeMutator; + + protected Method minuteMutator; + + protected Method secondMutator; + + protected boolean valueIsAdjusting; + + protected boolean valueModelIsAdjusting; + + protected DmsCoordinateConverter coordinateConverter; + + protected DefaultFormatterFactory formatterFactory; + + @Override + public void beforeInit(AbsoluteDmsCoordinateEditor ui) { + this.ui = ui; + // can't use the one from ConverterUtil since we deal with some internal states + this.coordinateConverter = new DmsCoordinateConverter(); + } + + @Override + public void afterInit(AbsoluteDmsCoordinateEditor ui) { + // nothing special to do here + } + + public void init(boolean longitudeEditor) { + + final AbsoluteDmsCoordinateEditorModel model = ui.getModel(); + + Preconditions.checkNotNull(model.getBean(), "could not find bean in " + ui); + Preconditions.checkNotNull(model.getPropertyDegree(), "could not find propertyDegree in " + ui); + Preconditions.checkNotNull(model.getPropertyMinute(), "could not find propertyMinute in " + ui); + Preconditions.checkNotNull(model.getPropertySecond(), "could not find propertySecond in " + ui); + + Object bean = model.getBean(); + + degreeMutator = BeanUIUtil.getMutator(bean, model.getPropertyDegree()); + Preconditions.checkNotNull(degreeMutator, "could not find mutator for " + model.getPropertyDegree()); + + minuteMutator = BeanUIUtil.getMutator(bean, model.getPropertyMinute()); + Preconditions.checkNotNull(minuteMutator, "could not find mutator for " + model.getPropertyMinute()); + + secondMutator = BeanUIUtil.getMutator(bean, model.getPropertySecond()); + Preconditions.checkNotNull(secondMutator, "could not find mutator for " + model.getPropertySecond()); + + coordinateConverter.setForLongitude(longitudeEditor); + + { + // prepare unsigned formatter factory + String pattern = getMaskFormatterPattern(longitudeEditor); + MaskFormatterFromConverter<DmsCoordinate> maskFormatter; + try { + maskFormatter = MaskFormatterFromConverter.newFormatter( + DmsCoordinate.class, + pattern, coordinateConverter); + maskFormatter.setValidCharacters(" 01234567890"); + maskFormatter.setCommitsOnValidEdit(true); + formatterFactory = new DefaultFormatterFactory(maskFormatter); + } catch (ParseException e) { + // can't happen here + throw new RuntimeException(e); + } + } + + JFormattedTextField editor = ui.getEditor(); + editor.setFormatterFactory(formatterFactory); + editor.setFocusLostBehavior(JFormattedTextField.COMMIT); + + // When editor changes his value, propagate it to model + editor.addPropertyChangeListener("value", new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + DmsCoordinate newValue = (DmsCoordinate) evt.getNewValue(); + if (log.isDebugEnabled()) { + log.debug("Value has changed: " + newValue); + } + model.setValue(newValue); + } + }); + + // When model degre changed, let's push it back in bean + model.addPropertyChangeListener( + AbsoluteDmsCoordinateEditorModel.PROPERTY_DEGREE, + new ModelPropertyChangeListener(model, degreeMutator)); + + // When model minute changed, let's push it back in bean + model.addPropertyChangeListener( + AbsoluteDmsCoordinateEditorModel.PROPERTY_MINUTE, + new ModelPropertyChangeListener(model, minuteMutator)); + + // When model second changed, let's push it back in bean + model.addPropertyChangeListener( + AbsoluteDmsCoordinateEditorModel.PROPERTY_SECOND, + new ModelPropertyChangeListener(model, secondMutator)); + } + + public void setValue(DmsCoordinate value, boolean pushToModel) { + + if (valueModelIsAdjusting) { + // avoid re-entrant code + return; + } + + valueIsAdjusting = !pushToModel; + + try { + ui.getEditor().setValue(value); + } finally { + valueIsAdjusting = false; + } + } + + public void resetEditor() { + + // set null value to model + setValue(null, true); + + // use back unsigned format + ui.getEditor().setFormatterFactory(formatterFactory); + } + + protected String getMaskFormatterPattern(boolean longitudeEditor) { + String pattern = "**°**''**''''"; + if (longitudeEditor) { + // add one more degre + pattern = "*" + pattern; + } + return pattern; + } + + private class ModelPropertyChangeListener implements PropertyChangeListener { + + private final AbsoluteDmsCoordinateEditorModel model; + + private final Method mutator; + + private ModelPropertyChangeListener(AbsoluteDmsCoordinateEditorModel model, Method mutator) { + this.model = model; + this.mutator = mutator; + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (!valueIsAdjusting) { + Object newValue = evt.getNewValue(); + + try { + + valueModelIsAdjusting = true; + try { + mutator.invoke(model.getBean(), newValue); + } finally { + valueModelIsAdjusting = false; + } + + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } + + } +} diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmsCoordinateEditorModel.java b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmsCoordinateEditorModel.java new file mode 100644 index 0000000..81f3e60 --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmsCoordinateEditorModel.java @@ -0,0 +1,96 @@ +package org.nuiton.jaxx.widgets.gis.absolute; + +import org.nuiton.jaxx.widgets.gis.DmsCoordinate; + +import java.io.Serializable; + +/** + * Created on 9/2/14. + * + * @author Tony Chemit - chemit@codelutin.com + * @since XXX + */ +public class AbsoluteDmsCoordinateEditorModel extends DmsCoordinate { + + public static final String PROPERTY_BEAN = "bean"; + + public static final String PROPERTY_PROPERTY_DEGREE = "propertyDegree"; + + public static final String PROPERTY_PROPERTY_MINUTE = "propertyMinute"; + + public static final String PROPERTY_PROPERTY_SECOND = "propertySecond"; + + private static final long serialVersionUID = 1L; + + /** Bean where to push data. */ + protected Serializable bean; + + /** Name of the property of the bean to fire the change of the {@link #degree}. */ + protected String propertyDegree; + + /** Name of the property of the bean to fire the change of the {@link #minute}. */ + protected String propertyMinute; + + /** Name of the property of the bean to fire the change of the {@link #second}. */ + protected String propertySecond; + + public Serializable getBean() { + return bean; + } + + public void setBean(Serializable bean) { + Object oldValue = getBean(); + this.bean = bean; + firePropertyChange(PROPERTY_BEAN, oldValue, bean); + } + + public String getPropertyDegree() { + return propertyDegree; + } + + public void setPropertyDegree(String propertyDegree) { + Object oldValue = getPropertyDegree(); + this.propertyDegree = propertyDegree; + firePropertyChange(PROPERTY_PROPERTY_DEGREE, oldValue, propertyDegree); + } + + public String getPropertyMinute() { + return propertyMinute; + } + + public void setPropertyMinute(String propertyMinute) { + Object oldValue = getPropertyMinute(); + this.propertyMinute = propertyMinute; + firePropertyChange(PROPERTY_PROPERTY_MINUTE, oldValue, propertyMinute); + } + + public String getPropertySecond() { + return propertySecond; + } + + public void setPropertySecond(String propertySecond) { + Object oldValue = getPropertySecond(); + this.propertySecond = propertySecond; + firePropertyChange(PROPERTY_PROPERTY_SECOND, oldValue, propertySecond); + } + + public void setValue(DmsCoordinate value) { + setDegree(value == null ? null : value.getDegree()); + setMinute(value == null ? null : value.getMinute()); + setSecond(value == null ? null : value.getSecond()); + } + + public String getStringPattern() { + return COORDINATE_STRING_PATTERN; + } + + @Override + public boolean isSign() { + return false; + } + + @Override + public void setSign(boolean sign) { + // never use it + } +} \ No newline at end of file diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/CoordinateEditor.css b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/CoordinateEditor.css new file mode 100644 index 0000000..01a428a --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/CoordinateEditor.css @@ -0,0 +1,38 @@ +/* + * #%L + * JAXX :: Widgets + * %% + * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +#toolbarLeft { + floatable:false; + borderPainted:false; + visible:{isShowReset()}; +} + +#resetButton { + actionIcon:"coordinate-reset"; + toolTipText: {getShowResetTip()}; + focusable:false; + focusPainted:false; + enabled:{isEnabled()}; +} + +#editor { + enabled:{isEnabled()}; +} diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/CoordinatesEditor.css b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/CoordinatesEditor.css new file mode 100644 index 0000000..67dca50 --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/CoordinatesEditor.css @@ -0,0 +1,187 @@ +/* + * #%L + * ObServe :: Swing + * %% + * Copyright (C) 2008 - 2010 IRD, Codelutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +// ---------- +// Common +// ---------- + +AbsoluteDdCoordinateEditor { + bean: {model}; + showReset: {model.isShowResetButton()}; +} + +AbsoluteDmsCoordinateEditor { + bean: {model}; + showReset: {model.isShowResetButton()}; +} + +AbsoluteDmdCoordinateEditor { + bean: {model}; + showReset: {model.isShowResetButton()}; +} + +// ---------- +// Quandrant +// ---------- + +#quadrantLabel { + text:"jaxx.common.quadrant"; + labelFor:{quadrant}; +} + +#quadrant4 { + text:"jaxx.common.quadrant4"; + buttonGroup:"quadrantBG"; + selected:{handler.isQuadrantSelected(model.getQuadrant(), 4)}; +} + +#quadrant1 { + text:"jaxx.common.quadrant1"; + buttonGroup:"quadrantBG"; + selected:{handler.isQuadrantSelected(model.getQuadrant(), 1)}; +} + +#quadrant3 { + text:"jaxx.common.quadrant3"; + buttonGroup:"quadrantBG"; + selected:{handler.isQuadrantSelected(model.getQuadrant(), 3)}; +} + +#quadrant2 { + text:"jaxx.common.quadrant2"; + buttonGroup:"quadrantBG"; + selected:{handler.isQuadrantSelected(model.getQuadrant(), 2)}; +} + +// ---------- +// Latitude +// ---------- + +#latitudeLayout { + selected:{String.valueOf(model.getFormat())}; +} + +#latitudeLabel { + text:"jaxx.common.latitude"; + labelFor:{latitudeEditor}; +} + +#latitudeEditor { + layout:{latitudeLayout}; +} + +#latitudeDd { + propertyDegree: ddDegree; + propertyDecimal: ddDecimal; + bean:{latitudeModel}; + value: {latitudeModel.getDd()}; + showResetTip: {t("jaxx.coordinate.action.reset.latitude.tip")}; +} + +#latitudeDms { + propertyDegree: dmsDegree; + propertyMinute: dmsMinute; + propertySecond: dmsSecond; + bean:{latitudeModel}; + value: {latitudeModel.getDms()}; + showResetTip: {t("jaxx.coordinate.action.reset.latitude.tip")}; +} + +#latitudeDmd { + propertyDegree: dmdDegree; + propertyMinute: dmdMinute; + propertyDecimal: dmdDecimal; + bean:{latitudeModel}; + value: {latitudeModel.getDmd()}; + showResetTip: {t("jaxx.coordinate.action.reset.latitude.tip")}; +} + +// ---------- +// Longitude +// ---------- + +#longitudeLayout { + selected:{String.valueOf(model.getFormat())}; +} + +#longitudeLabel { + text:"jaxx.common.longitude"; + labelFor:{longitudeEditor}; +} + +#longitudeEditor { + layout:{longitudeLayout}; +} + +#longitudeDd { + propertyDegree: ddDegree; + propertyDecimal: ddDecimal; + bean:{longitudeModel}; + value: {longitudeModel.getDd()}; + showResetTip: {t("jaxx.coordinate.action.reset.longitude.tip")}; +} + +#longitudeDms { + propertyDegree: dmsDegree; + propertyMinute: dmsMinute; + propertySecond: dmsSecond; + bean:{longitudeModel}; + value: {longitudeModel.getDms()}; + showResetTip: {t("jaxx.coordinate.action.reset.longitude.tip")}; +} + +#longitudeDmd { + propertyDegree: dmdDegree; + propertyMinute: dmdMinute; + propertyDecimal: dmdDecimal; + bean:{longitudeModel}; + value: {longitudeModel.getDmd()}; + showResetTip: {t("jaxx.coordinate.action.reset.longitude.tip")}; +} + +// ---------- +// Format +// ---------- + +#ddFormat { + text:"jaxx.coordinate.format.dd"; + toolTipText:"jaxx.coordinate.format.dd.tip"; + value:{CoordinateFormat.dd}; + selected:{model.getFormat() == CoordinateFormat.dd}; + buttonGroup:coordinateFormat; +} + +#dmsFormat { + text:"jaxx.coordinate.format.dms"; + toolTipText:"jaxx.coordinate.format.dms.tip"; + value:{CoordinateFormat.dms}; + selected:{model.getFormat() == CoordinateFormat.dms}; + buttonGroup:coordinateFormat; +} + +#dmdFormat { + text:"jaxx.coordinate.format.dmd"; + toolTipText:"jaxx.coordinate.format.dmd.tip"; + value:{CoordinateFormat.dmd}; + selected:{model.getFormat() == CoordinateFormat.dmd}; + buttonGroup: coordinateFormat; +} \ No newline at end of file diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/CoordinatesEditor.jaxx b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/CoordinatesEditor.jaxx new file mode 100644 index 0000000..5a1e0f9 --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/CoordinatesEditor.jaxx @@ -0,0 +1,63 @@ +<JPanel constraints='BorderLayout.CENTER' layout='{new BorderLayout()}'> + + <import> + jaxx.runtime.swing.CardLayout2Ext + org.nuiton.jaxx.widgets.gis.CoordinateFormat + </import> + + <CoordinatesEditorModel id='model'/> + <AbsoluteCoordinateEditorModel id='latitudeModel' initializer='model.getLatitudeModel()'/> + <AbsoluteCoordinateEditorModel id='longitudeModel' initializer='model.getLongitudeModel()'/> + + <!-- validator --> + <BeanValidator id='validator' autoField='true' bean='model'> + <field name='latitude' component='latitudeEditor'/> + <field name='longitude' component='longitudeEditor'/> + </BeanValidator> + + <CardLayout2Ext id='latitudeLayout' constructorParams='this, "latitudeEditor"'/> + <CardLayout2Ext id='longitudeLayout' constructorParams='this, "longitudeEditor"'/> + + <Table id='coordinatesPanel' constraints='BorderLayout.CENTER'> + <row> + <cell rows='2'> + <JPanel id='quadrant' layout="{new GridLayout(2,2,0,0)}"> + <JToggleButton id='quadrant4' onActionPerformed='model.setQuadrant(4)'/> + <JToggleButton id='quadrant1' onActionPerformed='model.setQuadrant(1)'/> + <JToggleButton id='quadrant3' onActionPerformed='model.setQuadrant(3)'/> + <JToggleButton id='quadrant2' onActionPerformed='model.setQuadrant(2)'/> + </JPanel> + </cell> + <cell anchor='east'> + <JLabel id='latitudeLabel'/> + </cell> + <cell fill='both'> + <JPanel id='latitudeEditor'> + <AbsoluteDdCoordinateEditor id='latitudeDd' constraints='CoordinateFormat.dd.name()'/> + <AbsoluteDmsCoordinateEditor id='latitudeDms' constraints='CoordinateFormat.dms.name()'/> + <AbsoluteDmdCoordinateEditor id='latitudeDmd' constraints='CoordinateFormat.dmd.name()'/> + </JPanel> + </cell> + <cell rows='2'> + <JPanel id='formatPanel' layout='{new GridLayout(0,1,0,0)}'> + <JRadioButton id='ddFormat' onActionPerformed='model.setFormat(CoordinateFormat.dd)'/> + <JRadioButton id='dmsFormat' onActionPerformed='model.setFormat(CoordinateFormat.dms)'/> + <JRadioButton id='dmdFormat' onActionPerformed='model.setFormat(CoordinateFormat.dmd)'/> + </JPanel> + </cell> + </row> + <row> + <cell anchor='east'> + <JLabel id='longitudeLabel'/> + </cell> + <cell fill='both'> + <JPanel id='longitudeEditor'> + <AbsoluteDdCoordinateEditor id='longitudeDd' constraints='CoordinateFormat.dd.name()'/> + <AbsoluteDmsCoordinateEditor id='longitudeDms' constraints='CoordinateFormat.dms.name()'/> + <AbsoluteDmdCoordinateEditor id='longitudeDmd' constraints='CoordinateFormat.dmd.name()'/> + </JPanel> + </cell> + </row> + </Table> + +</JPanel> \ No newline at end of file diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/CoordinatesEditorHandler.java b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/CoordinatesEditorHandler.java new file mode 100644 index 0000000..c496400 --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/CoordinatesEditorHandler.java @@ -0,0 +1,41 @@ +package org.nuiton.jaxx.widgets.gis.absolute; + +import jaxx.runtime.spi.UIHandler; +import org.nuiton.jaxx.widgets.gis.CoordinateFormat; + +/** + * Created on 8/31/14. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.7 + */ +public class CoordinatesEditorHandler implements UIHandler<CoordinatesEditor> { + + @Override + public void beforeInit(CoordinatesEditor ui) { + + CoordinatesEditorModel model = new CoordinatesEditorModel(); + model.setFormat(CoordinateFormat.dd); + model.setQuadrant(0); + + ui.setContextValue(model); + + } + + @Override + public void afterInit(CoordinatesEditor ui) { + + ui.getLatitudeDd().init(false); + ui.getLatitudeDms().init(false); + ui.getLatitudeDmd().init(false); + + ui.getLongitudeDd().init(true); + ui.getLongitudeDms().init(true); + ui.getLongitudeDmd().init(true); + + } + + public boolean isQuadrantSelected(Integer value, int requiredValue) { + return value != null && value == requiredValue; + } +} diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/CoordinatesEditorModel.java b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/CoordinatesEditorModel.java new file mode 100644 index 0000000..6803f03 --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/CoordinatesEditorModel.java @@ -0,0 +1,233 @@ +package org.nuiton.jaxx.widgets.gis.absolute; + +import org.jdesktop.beans.AbstractSerializableBean; +import org.nuiton.jaxx.widgets.gis.CoordinateFormat; +import org.nuiton.jaxx.widgets.gis.CoordinateHelper; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +/** + * Created on 8/31/14. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.7 + */ +public class CoordinatesEditorModel extends AbstractSerializableBean { + + private static final long serialVersionUID = 1L; + + public static final String PROPERTY_LATITUDE = "latitude"; + + public static final String PROPERTY_LONGITUDE = "longitude"; + + public static final String PROPERTY_QUADRANT = "quadrant"; + + public static final String PROPERTY_FORMAT = "format"; + + public static final String PROPERTY_AUTO_POPUP_NUMBER_EDITOR = "autoPopupNumberEditor"; + + public static final String PROPERTY_SHOW_NUMBER_EDITOR_BUTTON = "showNumberEditorButton"; + + public static final String PROPERTY_SHOW_RESET_BUTTON = "showResetButton"; + + protected final AbsoluteCoordinateEditorModel latitudeModel = new AbsoluteCoordinateEditorModel(); + + protected final AbsoluteCoordinateEditorModel longitudeModel = new AbsoluteCoordinateEditorModel(); + + protected Integer quadrant; + + protected CoordinateFormat format; + + protected boolean autoPopupNumberEditor; + + protected boolean showNumberEditorButton; + + protected boolean showResetButton; + + private boolean formatIsAdjusting; + + public CoordinatesEditorModel() { + + latitudeModel.addPropertyChangeListener(new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (!formatIsAdjusting) { + fireLatitude(); + } + } + }); + + longitudeModel.addPropertyChangeListener(new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (!formatIsAdjusting) { + fireLongitude(); + } + } + }); + + addPropertyChangeListener(PROPERTY_QUADRANT, new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + fireLatitude(); + fireLongitude(); + } + }); + + addPropertyChangeListener(PROPERTY_FORMAT, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + + formatIsAdjusting = true; + + try { + + CoordinateFormat oldValue = (CoordinateFormat) evt.getOldValue(); + + updateFormat(oldValue); + + } finally { + + formatIsAdjusting = false; + + fireLatitude(); + fireLongitude(); + + } + } + }); + } + + public void init(Float latitude, Float longitude) { + + formatIsAdjusting = true; + + try { + Integer quadrant; + if (longitude == null || latitude == null) { + quadrant = null; + } else { + quadrant = CoordinateHelper.getQuadrant(longitude, latitude); + } + this.quadrant = quadrant; + this.latitudeModel.setValue(latitude); + this.longitudeModel.setValue(longitude); + + updateFormat(getFormat()); + + } finally { + + formatIsAdjusting = false; + + fireLatitude(); + fireLongitude(); + fireQuadrant(); + + } + } + + public boolean isShowResetButton() { + return showResetButton; + } + + public void setShowResetButton(boolean showResetButton) { + boolean oldValue = isShowResetButton(); + this.showResetButton = showResetButton; + firePropertyChange(PROPERTY_SHOW_RESET_BUTTON, oldValue, showResetButton); + } + + public boolean isAutoPopupNumberEditor() { + return autoPopupNumberEditor; + } + + public void setAutoPopupNumberEditor(boolean autoPopupNumberEditor) { + boolean oldValue = isAutoPopupNumberEditor(); + this.autoPopupNumberEditor = autoPopupNumberEditor; + firePropertyChange(PROPERTY_AUTO_POPUP_NUMBER_EDITOR, oldValue, autoPopupNumberEditor); + } + + public boolean isShowNumberEditorButton() { + return showNumberEditorButton; + } + + public void setShowNumberEditorButton(boolean showNumberEditorButton) { + boolean oldValue = isShowNumberEditorButton(); + this.showNumberEditorButton = showNumberEditorButton; + firePropertyChange(PROPERTY_SHOW_NUMBER_EDITOR_BUTTON, oldValue, showNumberEditorButton); + } + + public AbsoluteCoordinateEditorModel getLatitudeModel() { + return latitudeModel; + } + + public AbsoluteCoordinateEditorModel getLongitudeModel() { + return longitudeModel; + } + + public Float getLatitude() { + Float latitude = format == null ? null : CoordinateHelper.getSignedLatitude(quadrant, latitudeModel.getValue(format)); + return latitude; + } + + public void setLatitude(Float dd) { + // don't use it + } + + public Float getLongitude() { + Float longitude = format == null ? null : CoordinateHelper.getSignedLongitude(quadrant, longitudeModel.getValue(format)); + return longitude; + } + + public void setLongitude(Float dd) { + // don't use it + } + + public Integer getQuadrant() { + return quadrant; + } + + public void setQuadrant(Integer quadrant) { + Object oldValue = getQuadrant(); + this.quadrant = quadrant; + firePropertyChange(PROPERTY_QUADRANT, oldValue, quadrant); + } + + public CoordinateFormat getFormat() { + return format; + } + + public void setFormat(CoordinateFormat format) { + Object oldValue = getFormat(); + this.format = format; + firePropertyChange(PROPERTY_FORMAT, oldValue, format); + } + + protected void fireLatitude() { + firePropertyChange(PROPERTY_LATITUDE, null, getLatitude()); + } + + protected void fireLongitude() { + firePropertyChange(PROPERTY_LONGITUDE, null, getLongitude()); + } + + protected void fireQuadrant() { + firePropertyChange(PROPERTY_QUADRANT, null, getQuadrant()); + } + + protected void updateFormat(CoordinateFormat format) { + + if (format != null) { + + Float latitude = latitudeModel.getValue(format); + latitudeModel.setValue(latitude); + + Float longitude = longitudeModel.getValue(format); + longitudeModel.setValue(longitude); + + } + + } + +} diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/package-info.java b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/package-info.java new file mode 100644 index 0000000..50cc5e9 --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/package-info.java @@ -0,0 +1,8 @@ +/** + * Define some absolute editor using quadrant. + * + * Created on 9/2/14. + * @author Tony Chemit - chemit@codelutin.com + * @since 2.12 + */ +package org.nuiton.jaxx.widgets.gis.absolute; \ No newline at end of file diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/CoordinateEditor.css b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/CoordinateEditor.css new file mode 100644 index 0000000..01a428a --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/CoordinateEditor.css @@ -0,0 +1,38 @@ +/* + * #%L + * JAXX :: Widgets + * %% + * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +#toolbarLeft { + floatable:false; + borderPainted:false; + visible:{isShowReset()}; +} + +#resetButton { + actionIcon:"coordinate-reset"; + toolTipText: {getShowResetTip()}; + focusable:false; + focusPainted:false; + enabled:{isEnabled()}; +} + +#editor { + enabled:{isEnabled()}; +} diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDdCoordinateEditor.jaxx b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDdCoordinateEditor.jaxx new file mode 100644 index 0000000..528f951 --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDdCoordinateEditor.jaxx @@ -0,0 +1,57 @@ +<!-- + #%L + JAXX :: Widgets + %% + Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Lesser Public License for more details. + + You should have received a copy of the GNU General Lesser Public + License along with this program. If not, see + <http://www.gnu.org/licenses/lgpl-3.0.html>. + #L% + --> +<JPanel id='editorPanel' layout='{new BorderLayout()}' onFocusGained='editor.requestFocus()'> + <import> + org.nuiton.jaxx.widgets.gis.DdCoordinate + + java.io.Serializable + java.awt.BorderLayout + javax.swing.JFormattedTextField + </import> + + <style source="CoordinateEditor.css"/> + + <!-- show reset property --> + <Boolean id='showReset' javaBean='false'/> + + <!-- show reset tip --> + <String id='showResetTip' javaBean=''/> + + <!-- model --> + <SignedDdCoordinateEditorModel id='model'/> + + <script><![CDATA[ +public void init(boolean longitudeEditor) { handler.init(longitudeEditor); } +public void setBean(Serializable bean) { model.setBean(bean); } +public void setPropertySign(String property ) { model.setPropertySign(property); } +public void setPropertyDegree(String property ) { model.setPropertyDegree(property); } +public void setPropertyDecimal(String property ) { model.setPropertyDecimal(property); } +public void setValue(DdCoordinate value) { handler.setValue(value, true); } +]]> + </script> + + <JToolBar id='toolbarLeft' constraints='BorderLayout.WEST'> + <JButton id='resetButton' onActionPerformed='handler.resetEditor()'/> + </JToolBar> + <JFormattedTextField id='editor' constraints='BorderLayout.CENTER' + onKeyReleased='handler.onKeyReleased(event)'/> +</JPanel> diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDdCoordinateEditorHandler.java b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDdCoordinateEditorHandler.java new file mode 100644 index 0000000..331aa68 --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDdCoordinateEditorHandler.java @@ -0,0 +1,298 @@ +package org.nuiton.jaxx.widgets.gis.signed; + +/* + * #%L + * JAXX :: Widgets + * %% + * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import com.google.common.base.Preconditions; +import jaxx.runtime.spi.UIHandler; +import jaxx.runtime.swing.editor.bean.BeanUIUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.jaxx.widgets.gis.DdCoordinate; +import org.nuiton.jaxx.widgets.gis.DdCoordinateConverter; +import org.nuiton.jaxx.widgets.gis.MaskFormatterFromConverter; + +import javax.swing.JFormattedTextField; +import javax.swing.text.DefaultFormatterFactory; +import java.awt.event.KeyEvent; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.lang.reflect.Method; +import java.text.ParseException; + +/** + * Created on 10/16/13. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 2.6 + */ +public class SignedDdCoordinateEditorHandler implements UIHandler<SignedDdCoordinateEditor> { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(SignedDdCoordinateEditorHandler.class); + + private SignedDdCoordinateEditor ui; + + protected Method signMutator; + + protected Method degreMutator; + + protected Method decimalMutator; + + protected boolean valueIsAdjusting; + + protected boolean valueModelIsAdjusting; + + protected DdCoordinateConverter signedConverter; + + protected DdCoordinateConverter unsignedConverter; + + protected DefaultFormatterFactory signedFormatterFactory; + + protected DefaultFormatterFactory unsignedFormatterFactory; + + @Override + public void beforeInit(SignedDdCoordinateEditor ui) { + this.ui = ui; + // can't use the one from ConverterUtil since we deal with some internal states + this.signedConverter = new DdCoordinateConverter(); + this.signedConverter.setUseSign(true); + this.unsignedConverter = new DdCoordinateConverter(); + } + + @Override + public void afterInit(SignedDdCoordinateEditor ui) { + // nothing special to do here + } + + public void init(boolean longitudeEditor) { + + final SignedDdCoordinateEditorModel model = ui.getModel(); + + Preconditions.checkNotNull(model.getBean(), "could not find bean in " + ui); + Preconditions.checkNotNull(model.getPropertySign(), "could not find propertySign in " + ui); + Preconditions.checkNotNull(model.getPropertyDegree(), "could not find propertyDegree in " + ui); + Preconditions.checkNotNull(model.getPropertyDecimal(), "could not find propertyDecimal in " + ui); + + Object bean = model.getBean(); + signMutator = BeanUIUtil.getMutator(bean, model.getPropertySign()); + Preconditions.checkNotNull(signMutator, "could not find mutator for " + model.getPropertySign()); + + degreMutator = BeanUIUtil.getMutator(bean, model.getPropertyDegree()); + Preconditions.checkNotNull(degreMutator, "could not find mutator for " + model.getPropertyDegree()); + + decimalMutator = BeanUIUtil.getMutator(bean, model.getPropertyDecimal()); + Preconditions.checkNotNull(decimalMutator, "could not find mutator for " + model.getPropertyDecimal()); + + signedConverter.setForLongitude(longitudeEditor); + unsignedConverter.setForLongitude(longitudeEditor); + + { + // prepare unsigned formatter factory + String pattern = getMaskFormatterPattern(longitudeEditor, false); + MaskFormatterFromConverter<DdCoordinate> maskFormatter; + try { + maskFormatter = MaskFormatterFromConverter.newFormatter( + DdCoordinate.class, + pattern, unsignedConverter); + maskFormatter.setValidCharacters(" 01234567890"); + maskFormatter.setCommitsOnValidEdit(true); + unsignedFormatterFactory = new DefaultFormatterFactory(maskFormatter); + } catch (ParseException e) { + // can't happen here + throw new RuntimeException(e); + } + } + { + // prepare signed formatter factory + String pattern = getMaskFormatterPattern(longitudeEditor, true); + MaskFormatterFromConverter<DdCoordinate> maskFormatter; + try { + maskFormatter = MaskFormatterFromConverter.newFormatter( + DdCoordinate.class, + pattern, signedConverter); + maskFormatter.setValidCharacters(" 01234567890"); + maskFormatter.setCommitsOnValidEdit(true); + signedFormatterFactory = new DefaultFormatterFactory(maskFormatter); + } catch (ParseException e) { + // can't happen here + throw new RuntimeException(e); + } + } + + JFormattedTextField editor = ui.getEditor(); + editor.setFormatterFactory(model.isSign() ? + signedFormatterFactory : + unsignedFormatterFactory); + editor.setFocusLostBehavior(JFormattedTextField.COMMIT); + + // When editor changes his value, propagate it to model + editor.addPropertyChangeListener("value", new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + DdCoordinate newValue = (DdCoordinate) evt.getNewValue(); + if (log.isDebugEnabled()) { + log.debug("Value has changed: " + newValue); + } + model.setValue(newValue); + } + }); + + // When model sign changed, let's push it back in bean + model.addPropertyChangeListener( + SignedDdCoordinateEditorModel.PROPERTY_SIGN, + new ModelPropertyChangeListener(model, signMutator)); + + // When model degre changed, let's push it back in bean + model.addPropertyChangeListener( + SignedDdCoordinateEditorModel.PROPERTY_DEGREE, + new ModelPropertyChangeListener(model, degreMutator)); + + // When model decimal changed, let's push it back in bean + model.addPropertyChangeListener( + SignedDdCoordinateEditorModel.PROPERTY_DECIMAL, + new ModelPropertyChangeListener(model, decimalMutator)); + } + + public void setValue(DdCoordinate value, boolean pushToModel) { + + if (valueModelIsAdjusting) { + // avoid re-entrant code + return; + } + + valueIsAdjusting = !pushToModel; + + try { + ui.getEditor().setValue(value); + } finally { + valueIsAdjusting = false; + } + } + + public void resetEditor() { + // set null value to model + setValue(null, true); + + // use back unsigned format + ui.getEditor().setFormatterFactory(unsignedFormatterFactory); + } + + public void onKeyReleased(KeyEvent e) { + + JFormattedTextField source = (JFormattedTextField) e.getSource(); + + char keyChar = e.getKeyChar(); + int caretPosition = source.getCaretPosition(); + if (log.isDebugEnabled()) { + log.debug("Key pressed: " + keyChar + " (caret position: " + caretPosition + ")"); + } + + if (keyChar == '-') { + + DdCoordinate value = (DdCoordinate) source.getValue(); + + DefaultFormatterFactory newFactory; + + // try to switch unsigned to signed + + boolean useSign = ui.getModel().isSign(); + + if (useSign) { + + if (log.isDebugEnabled()) { + log.debug("Switch to unsigned"); + } + + newFactory = unsignedFormatterFactory; + + // remove a sign + caretPosition--; + } else { + // switch to signed + if (log.isDebugEnabled()) { + log.debug("Switch to signed"); + } + newFactory = signedFormatterFactory; + + // add a sign + caretPosition++; + } + + DdCoordinate newValue = DdCoordinate.valueOf(value); + newValue.setSign(!useSign); + + source.setFormatterFactory(newFactory); + source.setValue(newValue); + + e.consume(); + + source.setCaretPosition(caretPosition); + } + } + + protected String getMaskFormatterPattern(boolean longitudeEditor, boolean useSign) { + String pattern = "**.***"; + if (longitudeEditor) { + // add one more degre + pattern = "*" + pattern; + } + if (useSign) { + pattern = "-" + pattern; + } + return pattern; + } + + private class ModelPropertyChangeListener implements PropertyChangeListener { + + private final SignedDdCoordinateEditorModel model; + + private final Method mutator; + + private ModelPropertyChangeListener(SignedDdCoordinateEditorModel model, + Method mutator) { + this.model = model; + this.mutator = mutator; + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (!valueIsAdjusting) { + Object newValue = evt.getNewValue(); + + try { + + valueModelIsAdjusting = true; + try { + mutator.invoke(model.getBean(), newValue); + } finally { + valueModelIsAdjusting = false; + } + + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } + } +} diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDdCoordinateEditorModel.java b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDdCoordinateEditorModel.java new file mode 100644 index 0000000..85299e8 --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDdCoordinateEditorModel.java @@ -0,0 +1,108 @@ +package org.nuiton.jaxx.widgets.gis.signed; + +/* + * #%L + * JAXX :: Widgets + * %% + * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.nuiton.jaxx.widgets.gis.DdCoordinate; + +import java.io.Serializable; + +/** + * Created on 10/16/13. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 2.6 + */ +public class SignedDdCoordinateEditorModel extends DdCoordinate { + + public static final String PROPERTY_BEAN = "bean"; + + public static final String PROPERTY_PROPERTY_SIGN = "propertySign"; + + public static final String PROPERTY_PROPERTY_DEGREE = "propertyDegree"; + + public static final String PROPERTY_PROPERTY_DECIMAL = "propertyDecimal"; + + private static final long serialVersionUID = 1L; + + /** Bean where to push data. */ + protected Serializable bean; + + /** Name of the property of the bean to fire the change of the {@link #sign}. */ + protected String propertySign; + + /** Name of the property of the bean to fire the change of the {@link #degree}. */ + protected String propertyDegree; + + /** Name of the property of the bean to fire the change of the {@link #decimal}. */ + protected String propertyDecimal; + + public Serializable getBean() { + return bean; + } + + public void setBean(Serializable bean) { + Object oldValue = getBean(); + this.bean = bean; + firePropertyChange(PROPERTY_BEAN, oldValue, bean); + } + + public String getPropertySign() { + return propertySign; + } + + public void setPropertySign(String propertySign) { + Object oldValue = getPropertySign(); + this.propertySign = propertySign; + firePropertyChange(PROPERTY_PROPERTY_SIGN, oldValue, propertySign); + } + + public String getPropertyDegree() { + return propertyDegree; + } + + public void setPropertyDegree(String propertyDegree) { + Object oldValue = getPropertyDegree(); + this.propertyDegree = propertyDegree; + firePropertyChange(PROPERTY_PROPERTY_DEGREE, oldValue, propertyDegree); + } + + public String getPropertyDecimal() { + return propertyDecimal; + } + + public void setPropertyDecimal(String propertyDecimal) { + Object oldValue = getPropertyDecimal(); + this.propertyDecimal = propertyDecimal; + firePropertyChange(PROPERTY_PROPERTY_DECIMAL, oldValue, propertyDecimal); + } + + public void setValue(DdCoordinate value) { + setSign(value != null && value.isSign()); + setDegree(value == null ? null : value.getDegree()); + setDecimal(value == null ? null : value.getDecimal()); + } + + public String getStringPattern() { + return COORDINATE_STRING_PATTERN; + } +} diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmdCoordinateEditor.jaxx b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmdCoordinateEditor.jaxx new file mode 100644 index 0000000..85bef3f --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmdCoordinateEditor.jaxx @@ -0,0 +1,58 @@ +<!-- + #%L + JAXX :: Widgets + %% + Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Lesser Public License for more details. + + You should have received a copy of the GNU General Lesser Public + License along with this program. If not, see + <http://www.gnu.org/licenses/lgpl-3.0.html>. + #L% + --> +<JPanel id='editorPanel' layout='{new BorderLayout()}' onFocusGained='editor.requestFocus()'> + <import> + org.nuiton.jaxx.widgets.gis.DmdCoordinate + + java.io.Serializable + java.awt.BorderLayout + javax.swing.JFormattedTextField + </import> + + <style source="CoordinateEditor.css"/> + + <!-- show reset property --> + <Boolean id='showReset' javaBean='false'/> + + <!-- show reset tip --> + <String id='showResetTip' javaBean=''/> + + <!-- model --> + <SignedDmdCoordinateEditorModel id='model'/> + + <script><![CDATA[ +public void init(boolean longitudeEditor) { handler.init(longitudeEditor); } +public void setBean(Serializable bean) { model.setBean(bean); } +public void setPropertySign(String property ) { model.setPropertySign(property); } +public void setPropertyDegree(String property ) { model.setPropertyDegree(property); } +public void setPropertyMinute(String property ) { model.setPropertyMinute(property); } +public void setPropertyDecimal(String property ) { model.setPropertyDecimal(property); } +public void setValue(DmdCoordinate value) { handler.setValue(value, true); } +]]> + </script> + + <JToolBar id='toolbarLeft' constraints='BorderLayout.WEST'> + <JButton id='resetButton' onActionPerformed='handler.resetEditor()'/> + </JToolBar> + <JFormattedTextField id='editor' constraints='BorderLayout.CENTER' + onKeyReleased='handler.onKeyReleased(event)'/> +</JPanel> diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmdCoordinateEditorHandler.java b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmdCoordinateEditorHandler.java new file mode 100644 index 0000000..36310ef --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmdCoordinateEditorHandler.java @@ -0,0 +1,309 @@ +package org.nuiton.jaxx.widgets.gis.signed; + +/* + * #%L + * JAXX :: Widgets + * %% + * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import com.google.common.base.Preconditions; +import jaxx.runtime.spi.UIHandler; +import jaxx.runtime.swing.editor.bean.BeanUIUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.jaxx.widgets.gis.DmdCoordinate; +import org.nuiton.jaxx.widgets.gis.DmdCoordinateConverter; +import org.nuiton.jaxx.widgets.gis.MaskFormatterFromConverter; + +import javax.swing.JFormattedTextField; +import javax.swing.text.DefaultFormatterFactory; +import java.awt.event.KeyEvent; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.lang.reflect.Method; +import java.text.ParseException; + +/** + * Created on 10/16/13. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 2.6 + */ +public class SignedDmdCoordinateEditorHandler implements UIHandler<SignedDmdCoordinateEditor> { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(SignedDmdCoordinateEditorHandler.class); + + private SignedDmdCoordinateEditor ui; + + protected Method signMutator; + + protected Method degreMutator; + + protected Method minuteMutator; + + protected Method decimalMutator; + + protected boolean valueIsAdjusting; + + protected boolean valueModelIsAdjusting; + + protected DmdCoordinateConverter signedConverter; + + protected DmdCoordinateConverter unsignedConverter; + + protected DefaultFormatterFactory signedFormatterFactory; + + protected DefaultFormatterFactory unsignedFormatterFactory; + + @Override + public void beforeInit(SignedDmdCoordinateEditor ui) { + this.ui = ui; + // can't use the one from ConverterUtil since we deal with some internal states + this.signedConverter = new DmdCoordinateConverter(); + this.signedConverter.setUseSign(true); + this.unsignedConverter = new DmdCoordinateConverter(); + } + + @Override + public void afterInit(SignedDmdCoordinateEditor ui) { + // nothing special to do here + } + + public void init(boolean longitudeEditor) { + + final SignedDmdCoordinateEditorModel model = ui.getModel(); + + Preconditions.checkNotNull(model.getBean(), "could not find bean in " + ui); + Preconditions.checkNotNull(model.getPropertySign(), "could not find propertySign in " + ui); + Preconditions.checkNotNull(model.getPropertyDegree(), "could not find propertyDegree in " + ui); + Preconditions.checkNotNull(model.getPropertyMinute(), "could not find propertyMinute in " + ui); + Preconditions.checkNotNull(model.getPropertyDecimal(), "could not find propertyDecimal in " + ui); + + Object bean = model.getBean(); + signMutator = BeanUIUtil.getMutator(bean, model.getPropertySign()); + Preconditions.checkNotNull(signMutator, "could not find mutator for " + model.getPropertySign()); + + degreMutator = BeanUIUtil.getMutator(bean, model.getPropertyDegree()); + Preconditions.checkNotNull(degreMutator, "could not find mutator for " + model.getPropertyDegree()); + + minuteMutator = BeanUIUtil.getMutator(bean, model.getPropertyMinute()); + Preconditions.checkNotNull(minuteMutator, "could not find mutator for " + model.getPropertyMinute()); + + decimalMutator = BeanUIUtil.getMutator(bean, model.getPropertyDecimal()); + Preconditions.checkNotNull(decimalMutator, "could not find mutator for " + model.getPropertyDecimal()); + + signedConverter.setForLongitude(longitudeEditor); + unsignedConverter.setForLongitude(longitudeEditor); + + { + // prepare unsigned formatter factory + String pattern = getMaskFormatterPattern(longitudeEditor, false); + MaskFormatterFromConverter<DmdCoordinate> maskFormatter; + try { + maskFormatter = MaskFormatterFromConverter.newFormatter( + DmdCoordinate.class, + pattern, unsignedConverter); + maskFormatter.setValidCharacters(" 01234567890"); + maskFormatter.setCommitsOnValidEdit(true); + unsignedFormatterFactory = new DefaultFormatterFactory(maskFormatter); + } catch (ParseException e) { + // can't happen here + throw new RuntimeException(e); + } + } + { + // prepare signed formatter factory + String pattern = getMaskFormatterPattern(longitudeEditor, true); + MaskFormatterFromConverter<DmdCoordinate> maskFormatter; + try { + maskFormatter = MaskFormatterFromConverter.newFormatter( + DmdCoordinate.class, + pattern, signedConverter); + maskFormatter.setValidCharacters(" 01234567890"); + maskFormatter.setCommitsOnValidEdit(true); + signedFormatterFactory = new DefaultFormatterFactory(maskFormatter); + } catch (ParseException e) { + // can't happen here + throw new RuntimeException(e); + } + } + + JFormattedTextField editor = ui.getEditor(); + editor.setFormatterFactory(model.isSign() ? + signedFormatterFactory : + unsignedFormatterFactory); + editor.setFocusLostBehavior(JFormattedTextField.COMMIT); + + // When editor changes his value, propagate it to model + editor.addPropertyChangeListener("value", new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + DmdCoordinate newValue = (DmdCoordinate) evt.getNewValue(); + if (log.isDebugEnabled()) { + log.debug("Value has changed: " + newValue); + } + model.setValue(newValue); + } + }); + + // When model sign changed, let's push it back in bean + model.addPropertyChangeListener( + SignedDmdCoordinateEditorModel.PROPERTY_SIGN, + new ModelPropertyChangeListener(model, signMutator)); + + // When model degre changed, let's push it back in bean + model.addPropertyChangeListener( + SignedDmdCoordinateEditorModel.PROPERTY_DEGREE, + new ModelPropertyChangeListener(model, degreMutator)); + + // When model minute changed, let's push it back in bean + model.addPropertyChangeListener( + SignedDmdCoordinateEditorModel.PROPERTY_MINUTE, + new ModelPropertyChangeListener(model, minuteMutator)); + + // When model decimal changed, let's push it back in bean + model.addPropertyChangeListener( + SignedDmdCoordinateEditorModel.PROPERTY_DECIMAL, + new ModelPropertyChangeListener(model, decimalMutator)); + } + + public void setValue(DmdCoordinate value, boolean pushToModel) { + + if (valueModelIsAdjusting) { + // avoid re-entrant code + return; + } + + valueIsAdjusting = !pushToModel; + + try { + ui.getEditor().setValue(value); + } finally { + valueIsAdjusting = false; + } + } + + public void resetEditor() { + // set null value to model + setValue(null, true); + + // use back unsigned format + ui.getEditor().setFormatterFactory(unsignedFormatterFactory); + } + + public void onKeyReleased(KeyEvent e) { + + JFormattedTextField source = (JFormattedTextField) e.getSource(); + + char keyChar = e.getKeyChar(); + int caretPosition = source.getCaretPosition(); + if (log.isDebugEnabled()) { + log.debug("Key pressed: " + keyChar + " (caret position: " + caretPosition + ")"); + } + + if (keyChar == '-') { + + DmdCoordinate value = (DmdCoordinate) source.getValue(); + + DefaultFormatterFactory newFactory; + + // try to switch unsigned to signed + + boolean useSign = ui.getModel().isSign(); + + if (useSign) { + + if (log.isDebugEnabled()) { + log.debug("Switch to unsigned"); + } + + newFactory = unsignedFormatterFactory; + + // remove a sign + caretPosition--; + } else { + // switch to signed + if (log.isDebugEnabled()) { + log.debug("Switch to signed"); + } + newFactory = signedFormatterFactory; + + // add a sign + caretPosition++; + } + + DmdCoordinate newValue = DmdCoordinate.valueOf(value); + newValue.setSign(!useSign); + + source.setFormatterFactory(newFactory); + source.setValue(newValue); + + e.consume(); + + source.setCaretPosition(caretPosition); + } + } + + protected String getMaskFormatterPattern(boolean longitudeEditor, boolean useSign) { + String pattern = "**°**''**"; + if (longitudeEditor) { + // add one more degre + pattern = "*" + pattern; + } + if (useSign) { + pattern = "-" + pattern; + } + return pattern; + } + + private class ModelPropertyChangeListener implements PropertyChangeListener { + + private final SignedDmdCoordinateEditorModel model; + + private final Method mutator; + + private ModelPropertyChangeListener(SignedDmdCoordinateEditorModel model, + Method mutator) { + this.model = model; + this.mutator = mutator; + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (!valueIsAdjusting) { + Object newValue = evt.getNewValue(); + + try { + + valueModelIsAdjusting = true; + try { + mutator.invoke(model.getBean(), newValue); + } finally { + valueModelIsAdjusting = false; + } + + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } + } +} diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmdCoordinateEditorModel.java b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmdCoordinateEditorModel.java new file mode 100644 index 0000000..0f444d1 --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmdCoordinateEditorModel.java @@ -0,0 +1,125 @@ +package org.nuiton.jaxx.widgets.gis.signed; + +/* + * #%L + * JAXX :: Widgets + * %% + * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.nuiton.jaxx.widgets.gis.DmdCoordinate; + +import java.io.Serializable; + +/** + * Created on 10/16/13. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 2.6 + */ +public class SignedDmdCoordinateEditorModel extends DmdCoordinate { + + public static final String PROPERTY_BEAN = "bean"; + + public static final String PROPERTY_PROPERTY_SIGN = "propertySign"; + + public static final String PROPERTY_PROPERTY_DEGREE = "propertyDegree"; + + public static final String PROPERTY_PROPERTY_MINUTE = "propertyMinute"; + + public static final String PROPERTY_PROPERTY_DECIMAL = "propertyDecimal"; + + private static final long serialVersionUID = 1L; + + /** Bean where to push data. */ + protected Serializable bean; + + /** Name of the property of the bean to fire the change of the {@link #sign}. */ + protected String propertySign; + + /** Name of the property of the bean to fire the change of the {@link #degree}. */ + protected String propertyDegree; + + /** Name of the property of the bean to fire the change of the {@link #minute}. */ + protected String propertyMinute; + + /** Name of the property of the bean to fire the change of the {@link #decimal}. */ + protected String propertyDecimal; + + public Serializable getBean() { + return bean; + } + + public void setBean(Serializable bean) { + Object oldValue = getBean(); + this.bean = bean; + firePropertyChange(PROPERTY_BEAN, oldValue, bean); + } + + public String getPropertySign() { + return propertySign; + } + + public void setPropertySign(String propertySign) { + Object oldValue = getPropertySign(); + this.propertySign = propertySign; + firePropertyChange(PROPERTY_PROPERTY_SIGN, oldValue, propertySign); + } + + public String getPropertyDegree() { + return propertyDegree; + } + + public void setPropertyDegree(String propertyDegree) { + Object oldValue = getPropertyDegree(); + this.propertyDegree = propertyDegree; + firePropertyChange(PROPERTY_PROPERTY_DEGREE, oldValue, propertyDegree); + } + + public String getPropertyMinute() { + return propertyMinute; + } + + public void setPropertyMinute(String propertyMinute) { + Object oldValue = getPropertyMinute(); + this.propertyMinute = propertyMinute; + firePropertyChange(PROPERTY_PROPERTY_MINUTE, oldValue, propertyMinute); + } + + public String getPropertyDecimal() { + return propertyDecimal; + } + + public void setPropertyDecimal(String propertyDecimal) { + Object oldValue = getPropertyDecimal(); + this.propertyDecimal = propertyDecimal; + firePropertyChange(PROPERTY_PROPERTY_DECIMAL, oldValue, propertyDecimal); + } + + public void setValue(DmdCoordinate value) { + setSign(value != null && value.isSign()); + setDegree(value == null ? null : value.getDegree()); + setMinute(value == null ? null : value.getMinute()); + setDecimal(value == null ? null : value.getDecimal()); + } + + public String getStringPattern() { + String pattern = COORDINATE_STRING_PATTERN; + return pattern; + } +} diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmsCoordinateEditor.jaxx b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmsCoordinateEditor.jaxx new file mode 100644 index 0000000..012aa0d --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmsCoordinateEditor.jaxx @@ -0,0 +1,58 @@ +<!-- + #%L + JAXX :: Widgets + %% + Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Lesser Public License for more details. + + You should have received a copy of the GNU General Lesser Public + License along with this program. If not, see + <http://www.gnu.org/licenses/lgpl-3.0.html>. + #L% + --> +<JPanel id='editorPanel' layout='{new BorderLayout()}' onFocusGained='editor.requestFocus()'> + <import> + org.nuiton.jaxx.widgets.gis.DmsCoordinate + + java.io.Serializable + java.awt.BorderLayout + javax.swing.JFormattedTextField + </import> + + <style source="CoordinateEditor.css"/> + + <!-- show reset property --> + <Boolean id='showReset' javaBean='false'/> + + <!-- show reset tip --> + <String id='showResetTip' javaBean=''/> + + <!-- model --> + <SignedDmsCoordinateEditorModel id='model'/> + + <script><![CDATA[ +public void init(boolean longitudeEditor) { handler.init(longitudeEditor); } +public void setBean(Serializable bean) { model.setBean(bean); } +public void setPropertySign(String property ) { model.setPropertySign(property); } +public void setPropertyDegree(String property ) { model.setPropertyDegree(property); } +public void setPropertyMinute(String property ) { model.setPropertyMinute(property); } +public void setPropertySecond(String property ) { model.setPropertySecond(property); } +public void setValue(DmsCoordinate value) { handler.setValue(value, true); } +]]> + </script> + + <JToolBar id='toolbarLeft' constraints='BorderLayout.WEST'> + <JButton id='resetButton' onActionPerformed='handler.resetEditor()'/> + </JToolBar> + <JFormattedTextField id='editor' constraints='BorderLayout.CENTER' + onKeyReleased='handler.onKeyReleased(event)'/> +</JPanel> diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmsCoordinateEditorHandler.java b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmsCoordinateEditorHandler.java new file mode 100644 index 0000000..1402dce --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmsCoordinateEditorHandler.java @@ -0,0 +1,311 @@ +package org.nuiton.jaxx.widgets.gis.signed; + +/* + * #%L + * JAXX :: Widgets + * %% + * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import com.google.common.base.Preconditions; +import jaxx.runtime.spi.UIHandler; +import jaxx.runtime.swing.editor.bean.BeanUIUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.jaxx.widgets.gis.DmsCoordinate; +import org.nuiton.jaxx.widgets.gis.DmsCoordinateConverter; +import org.nuiton.jaxx.widgets.gis.MaskFormatterFromConverter; + +import javax.swing.JFormattedTextField; +import javax.swing.text.DefaultFormatterFactory; +import java.awt.event.KeyEvent; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.lang.reflect.Method; +import java.text.ParseException; + +/** + * Created on 10/16/13. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 2.6 + */ +public class SignedDmsCoordinateEditorHandler implements UIHandler<SignedDmsCoordinateEditor> { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(SignedDmsCoordinateEditorHandler.class); + + protected SignedDmsCoordinateEditor ui; + + protected Method signMutator; + + protected Method degreMutator; + + protected Method minuteMutator; + + protected Method secondMutator; + + protected boolean valueIsAdjusting; + + protected boolean valueModelIsAdjusting; + + protected DmsCoordinateConverter signedConverter; + + protected DmsCoordinateConverter unsignedConverter; + + protected DefaultFormatterFactory signedFormatterFactory; + + protected DefaultFormatterFactory unsignedFormatterFactory; + + @Override + public void beforeInit(SignedDmsCoordinateEditor ui) { + this.ui = ui; + // can't use the one from ConverterUtil since we deal with some internal states + this.signedConverter = new DmsCoordinateConverter(); + this.signedConverter.setUseSign(true); + this.unsignedConverter = new DmsCoordinateConverter(); + } + + @Override + public void afterInit(SignedDmsCoordinateEditor ui) { + // nothing special to do here + } + + public void init(boolean longitudeEditor) { + + final SignedDmsCoordinateEditorModel model = ui.getModel(); + + Preconditions.checkNotNull(model.getBean(), "could not find bean in " + ui); + Preconditions.checkNotNull(model.getPropertySign(), "could not find propertySign in " + ui); + Preconditions.checkNotNull(model.getPropertyDegree(), "could not find propertyDegree in " + ui); + Preconditions.checkNotNull(model.getPropertyMinute(), "could not find propertyMinute in " + ui); + Preconditions.checkNotNull(model.getPropertySecond(), "could not find propertySecond in " + ui); + + Object bean = model.getBean(); + signMutator = BeanUIUtil.getMutator(bean, model.getPropertySign()); + Preconditions.checkNotNull(signMutator, "could not find mutator for " + model.getPropertySign()); + + degreMutator = BeanUIUtil.getMutator(bean, model.getPropertyDegree()); + Preconditions.checkNotNull(degreMutator, "could not find mutator for " + model.getPropertyDegree()); + + minuteMutator = BeanUIUtil.getMutator(bean, model.getPropertyMinute()); + Preconditions.checkNotNull(minuteMutator, "could not find mutator for " + model.getPropertyMinute()); + + secondMutator = BeanUIUtil.getMutator(bean, model.getPropertySecond()); + Preconditions.checkNotNull(secondMutator, "could not find mutator for " + model.getPropertySecond()); + + signedConverter.setForLongitude(longitudeEditor); + unsignedConverter.setForLongitude(longitudeEditor); + + { + // prepare unsigned formatter factory + String pattern = getMaskFormatterPattern(longitudeEditor, false); + MaskFormatterFromConverter<DmsCoordinate> maskFormatter; + try { + maskFormatter = MaskFormatterFromConverter.newFormatter( + DmsCoordinate.class, + pattern, unsignedConverter); + maskFormatter.setValidCharacters(" 01234567890"); + maskFormatter.setCommitsOnValidEdit(true); + unsignedFormatterFactory = new DefaultFormatterFactory(maskFormatter); + } catch (ParseException e) { + // can't happen here + throw new RuntimeException(e); + } + } + { + // prepare signed formatter factory + String pattern = getMaskFormatterPattern(longitudeEditor, true); + MaskFormatterFromConverter<DmsCoordinate> maskFormatter; + try { + maskFormatter = MaskFormatterFromConverter.newFormatter( + DmsCoordinate.class, + pattern, signedConverter); + maskFormatter.setValidCharacters(" 01234567890"); + maskFormatter.setCommitsOnValidEdit(true); + signedFormatterFactory = new DefaultFormatterFactory(maskFormatter); + } catch (ParseException e) { + // can't happen here + throw new RuntimeException(e); + } + } + + JFormattedTextField editor = ui.getEditor(); + editor.setFormatterFactory(model.isSign() ? + signedFormatterFactory : + unsignedFormatterFactory); + editor.setFocusLostBehavior(JFormattedTextField.COMMIT); + + // When editor changes his value, propagate it to model + editor.addPropertyChangeListener("value", new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + DmsCoordinate newValue = (DmsCoordinate) evt.getNewValue(); + if (log.isDebugEnabled()) { + log.debug("Value has changed: " + newValue); + } + model.setValue(newValue); + } + }); + + // When model sign changed, let's push it back in bean + model.addPropertyChangeListener( + SignedDmsCoordinateEditorModel.PROPERTY_SIGN, + new ModelPropertyChangeListener(model, signMutator)); + + // When model degre changed, let's push it back in bean + model.addPropertyChangeListener( + SignedDmsCoordinateEditorModel.PROPERTY_DEGREE, + new ModelPropertyChangeListener(model, degreMutator)); + + // When model minute changed, let's push it back in bean + model.addPropertyChangeListener( + SignedDmsCoordinateEditorModel.PROPERTY_MINUTE, + new ModelPropertyChangeListener(model, minuteMutator)); + + // When model second changed, let's push it back in bean + model.addPropertyChangeListener( + SignedDmsCoordinateEditorModel.PROPERTY_SECOND, + new ModelPropertyChangeListener(model, secondMutator)); + } + + public void setValue(DmsCoordinate value, boolean pushToModel) { + + if (valueModelIsAdjusting) { + // avoid re-entrant code + return; + } + + valueIsAdjusting = !pushToModel; + + try { + ui.getEditor().setValue(value); + } finally { + valueIsAdjusting = false; + } + } + + public void resetEditor() { + + // set null value to model + setValue(null, true); + + // use back unsigned format + ui.getEditor().setFormatterFactory(unsignedFormatterFactory); + } + + public void onKeyReleased(KeyEvent e) { + + JFormattedTextField source = (JFormattedTextField) e.getSource(); + + char keyChar = e.getKeyChar(); + int caretPosition = source.getCaretPosition(); + if (log.isDebugEnabled()) { + log.debug("Key pressed: " + keyChar + " (caret position: " + caretPosition + ")"); + } + + if (keyChar == '-') { + + DmsCoordinate value = (DmsCoordinate) source.getValue(); + + DefaultFormatterFactory newFactory; + + // try to switch unsigned to signed + + boolean useSign = ui.getModel().isSign(); + + if (useSign) { + + if (log.isDebugEnabled()) { + log.debug("Switch to unsigned"); + } + + newFactory = unsignedFormatterFactory; + + // remove a sign + caretPosition--; + } else { + // switch to signed + if (log.isDebugEnabled()) { + log.debug("Switch to signed"); + } + newFactory = signedFormatterFactory; + + // add a sign + caretPosition++; + } + + DmsCoordinate newValue = DmsCoordinate.valueOf(value); + newValue.setSign(!useSign); + + source.setFormatterFactory(newFactory); + source.setValue(newValue); + + e.consume(); + + source.setCaretPosition(caretPosition); + } + } + + protected String getMaskFormatterPattern(boolean longitudeEditor, + boolean useSign) { + String pattern = "**°**''**''''"; + if (longitudeEditor) { + // add one more degre + pattern = "*" + pattern; + } + if (useSign) { + pattern = "-" + pattern; + } + return pattern; + } + + private class ModelPropertyChangeListener implements PropertyChangeListener { + + private final SignedDmsCoordinateEditorModel model; + + private final Method mutator; + + private ModelPropertyChangeListener(SignedDmsCoordinateEditorModel model, Method mutator) { + this.model = model; + this.mutator = mutator; + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (!valueIsAdjusting) { + Object newValue = evt.getNewValue(); + + try { + + valueModelIsAdjusting = true; + try { + mutator.invoke(model.getBean(), newValue); + } finally { + valueModelIsAdjusting = false; + } + + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } + + } +} diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmsCoordinateEditorModel.java b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmsCoordinateEditorModel.java new file mode 100644 index 0000000..d1627bc --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmsCoordinateEditorModel.java @@ -0,0 +1,124 @@ +package org.nuiton.jaxx.widgets.gis.signed; + +/* + * #%L + * JAXX :: Widgets + * %% + * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.nuiton.jaxx.widgets.gis.DmsCoordinate; + +import java.io.Serializable; + +/** + * Created on 10/16/13. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 2.6 + */ +public class SignedDmsCoordinateEditorModel extends DmsCoordinate { + + public static final String PROPERTY_BEAN = "bean"; + + public static final String PROPERTY_PROPERTY_SIGN = "propertySign"; + + public static final String PROPERTY_PROPERTY_DEGREE = "propertyDegree"; + + public static final String PROPERTY_PROPERTY_MINUTE = "propertyMinute"; + + public static final String PROPERTY_PROPERTY_SECOND = "propertySecond"; + + private static final long serialVersionUID = 1L; + + /** Bean where to push data. */ + protected Serializable bean; + + /** Name of the property of the bean to fire the change of the {@link #sign}. */ + protected String propertySign; + + /** Name of the property of the bean to fire the change of the {@link #degree}. */ + protected String propertyDegree; + + /** Name of the property of the bean to fire the change of the {@link #minute}. */ + protected String propertyMinute; + + /** Name of the property of the bean to fire the change of the {@link #second}. */ + protected String propertySecond; + + public Serializable getBean() { + return bean; + } + + public void setBean(Serializable bean) { + Object oldValue = getBean(); + this.bean = bean; + firePropertyChange(PROPERTY_BEAN, oldValue, bean); + } + + public String getPropertySign() { + return propertySign; + } + + public void setPropertySign(String propertySign) { + Object oldValue = getPropertySign(); + this.propertySign = propertySign; + firePropertyChange(PROPERTY_PROPERTY_SIGN, oldValue, propertySign); + } + + public String getPropertyDegree() { + return propertyDegree; + } + + public void setPropertyDegree(String propertyDegree) { + Object oldValue = getPropertyDegree(); + this.propertyDegree = propertyDegree; + firePropertyChange(PROPERTY_PROPERTY_DEGREE, oldValue, propertyDegree); + } + + public String getPropertyMinute() { + return propertyMinute; + } + + public void setPropertyMinute(String propertyMinute) { + Object oldValue = getPropertyMinute(); + this.propertyMinute = propertyMinute; + firePropertyChange(PROPERTY_PROPERTY_MINUTE, oldValue, propertyMinute); + } + + public String getPropertySecond() { + return propertySecond; + } + + public void setPropertySecond(String propertySecond) { + Object oldValue = getPropertySecond(); + this.propertySecond = propertySecond; + firePropertyChange(PROPERTY_PROPERTY_SECOND, oldValue, propertySecond); + } + + public void setValue(DmsCoordinate value) { + setSign(value != null && value.isSign()); + setDegree(value == null ? null : value.getDegree()); + setMinute(value == null ? null : value.getMinute()); + setSecond(value == null ? null : value.getSecond()); + } + + public String getStringPattern() { + return COORDINATE_STRING_PATTERN; + } +} diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/package-info.java b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/package-info.java new file mode 100644 index 0000000..bf02f6a --- /dev/null +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/signed/package-info.java @@ -0,0 +1,8 @@ +/** + * Define some signed editor. + * + * Created on 9/2/14. + * @author Tony Chemit - chemit@codelutin.com + * @since 2.12 + */ +package org.nuiton.jaxx.widgets.gis.signed; \ No newline at end of file diff --git a/jaxx-widgets-gis/src/main/resources/META-INF/services/org.nuiton.converter.NuitonConverter b/jaxx-widgets-gis/src/main/resources/META-INF/services/org.nuiton.converter.NuitonConverter new file mode 100644 index 0000000..b9680a9 --- /dev/null +++ b/jaxx-widgets-gis/src/main/resources/META-INF/services/org.nuiton.converter.NuitonConverter @@ -0,0 +1,3 @@ +org.nuiton.jaxx.widgets.gis.DmsCoordinateConverter +org.nuiton.jaxx.widgets.gis.DmdCoordinateConverter +org.nuiton.jaxx.widgets.gis.DdCoordinateConverter \ No newline at end of file diff --git a/jaxx-widgets-gis/src/main/resources/i18n/jaxx-widgets-gis_en_GB.properties b/jaxx-widgets-gis/src/main/resources/i18n/jaxx-widgets-gis_en_GB.properties new file mode 100644 index 0000000..9ae0ce5 --- /dev/null +++ b/jaxx-widgets-gis/src/main/resources/i18n/jaxx-widgets-gis_en_GB.properties @@ -0,0 +1,17 @@ +jaxx.common.latitude= +jaxx.common.longitude= +jaxx.common.quadrant1= +jaxx.common.quadrant2= +jaxx.common.quadrant3= +jaxx.common.quadrant4= +jaxx.coordinate.action.reset.latitude.tip= +jaxx.coordinate.action.reset.longitude.tip= +jaxx.coordinate.format.dd= +jaxx.coordinate.format.dd.tip= +jaxx.coordinate.format.dmd= +jaxx.coordinate.format.dmd.tip= +jaxx.coordinate.format.dms= +jaxx.coordinate.format.dms.tip= +jaxx.error.no.convertor.coordinateDd= +jaxx.error.no.convertor.coordinateDmd=Impossible de convert form (or to) a DMD coordinate (incoming value\: %s) +jaxx.error.no.convertor.coordinateDms=Impossible de convert form (or to) a DMS coordinate (incoming value\: %s) diff --git a/jaxx-widgets-gis/src/main/resources/i18n/jaxx-widgets-gis_es_ES.properties b/jaxx-widgets-gis/src/main/resources/i18n/jaxx-widgets-gis_es_ES.properties new file mode 100644 index 0000000..8bef7d9 --- /dev/null +++ b/jaxx-widgets-gis/src/main/resources/i18n/jaxx-widgets-gis_es_ES.properties @@ -0,0 +1,17 @@ +jaxx.common.latitude= +jaxx.common.longitude= +jaxx.common.quadrant1= +jaxx.common.quadrant2= +jaxx.common.quadrant3= +jaxx.common.quadrant4= +jaxx.coordinate.action.reset.latitude.tip= +jaxx.coordinate.action.reset.longitude.tip= +jaxx.coordinate.format.dd= +jaxx.coordinate.format.dd.tip= +jaxx.coordinate.format.dmd= +jaxx.coordinate.format.dmd.tip= +jaxx.coordinate.format.dms= +jaxx.coordinate.format.dms.tip= +jaxx.error.no.convertor.coordinateDd= +jaxx.error.no.convertor.coordinateDmd= +jaxx.error.no.convertor.coordinateDms= diff --git a/jaxx-widgets-gis/src/main/resources/i18n/jaxx-widgets-gis_fr_FR.properties b/jaxx-widgets-gis/src/main/resources/i18n/jaxx-widgets-gis_fr_FR.properties new file mode 100644 index 0000000..ee122f0 --- /dev/null +++ b/jaxx-widgets-gis/src/main/resources/i18n/jaxx-widgets-gis_fr_FR.properties @@ -0,0 +1,17 @@ +jaxx.common.latitude=Latitude +jaxx.common.longitude=Longitude +jaxx.common.quadrant1=(1) NE +jaxx.common.quadrant2=(2) SE +jaxx.common.quadrant3=(3) SW +jaxx.common.quadrant4=(4) NW +jaxx.coordinate.action.reset.latitude.tip=Réinitialiser la latitude +jaxx.coordinate.action.reset.longitude.tip=Réinitialiser la longitude +jaxx.coordinate.format.dd=DD +jaxx.coordinate.format.dd.tip=Format Degré / Décimal +jaxx.coordinate.format.dmd=DMD +jaxx.coordinate.format.dmd.tip=Format Degré / Minute / Seconde +jaxx.coordinate.format.dms=DMS +jaxx.coordinate.format.dms.tip=Format Degré / Minute décimal +jaxx.error.no.convertor.coordinateDd=Impossible de convertir en (ou depuis) une coordonée DD depuis la valeur %s +jaxx.error.no.convertor.coordinateDmd=Impossible de convertir en (ou depuis) une coordonée DMD depuis la valeur %s +jaxx.error.no.convertor.coordinateDms=Impossible de convertir en (ou depuis) une coordonée DMS depuis la valeur %s diff --git a/jaxx-widgets-gis/src/main/resources/icons/action-coordinate-reset.png b/jaxx-widgets-gis/src/main/resources/icons/action-coordinate-reset.png new file mode 100644 index 0000000..0fb00f9 Binary files /dev/null and b/jaxx-widgets-gis/src/main/resources/icons/action-coordinate-reset.png differ diff --git a/jaxx-widgets-gis/src/site/site.xml b/jaxx-widgets-gis/src/site/site.xml new file mode 100644 index 0000000..ba56de7 --- /dev/null +++ b/jaxx-widgets-gis/src/site/site.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + #%L + JAXX :: Widgets + %% + Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Lesser Public License for more details. + + You should have received a copy of the GNU General Lesser Public + License along with this program. If not, see + <http://www.gnu.org/licenses/lgpl-3.0.html>. + #L% + --> + +<project name="${project.name}"> + + <bannerLeft> + <name>${project.name}</name> + <src>${siteCommonResourcesUrl}/images/logos/jaxx-logo.png</src> + <href>index.html</href> + </bannerLeft> + + <body> + + <breadcrumbs> + <item name="${project.name}" href="index.html"/> + </breadcrumbs> + + <menu ref="parent"/> + + <menu ref="reports"/> + + </body> +</project> diff --git a/jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets/gis/DdCoordinateConverterTest.java b/jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets/gis/DdCoordinateConverterTest.java new file mode 100644 index 0000000..9718b5c --- /dev/null +++ b/jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets/gis/DdCoordinateConverterTest.java @@ -0,0 +1,95 @@ +package org.nuiton.jaxx.widgets.gis; + +import org.junit.Assert; +import org.junit.Test; +import org.nuiton.converter.ConverterUtil; + +/** + * Created on 9/2/14. + * + * @author Tony Chemit - chemit@codelutin.com + * @since XXX + */ +public class DdCoordinateConverterTest { + + + @Test + public void testConvert() throws Exception { + + ConverterUtil.initConverters(); + + testConversion(false, "- .4 ", DdCoordinate.valueOf(-0.4f)); + testConversion(false, " .4 ", DdCoordinate.valueOf(0.4f)); + testConversion(false, "- .04 ", DdCoordinate.valueOf(-0.04f)); + testConversion(false, " .04 ", DdCoordinate.valueOf(0.04f)); + testConversion(false, "- .004", DdCoordinate.valueOf(-0.004f)); + testConversion(false, " .004", DdCoordinate.valueOf(0.004f)); + testConversion(false, "- .044", DdCoordinate.valueOf(-0.044f)); + testConversion(false, " .044", DdCoordinate.valueOf(0.044f)); + testConversion(false, "- .444", DdCoordinate.valueOf(-0.444f)); + testConversion(false, " .444", DdCoordinate.valueOf(0.444f)); + testConversion(false, " .099", DdCoordinate.valueOf(false, null, 99)); + testConversion(false, " . ", DdCoordinate.empty()); + testConversion(false, " .099", DdCoordinate.valueOf(false, null, 99)); + testConversion(false, "39.099", DdCoordinate.valueOf(false, 39, 99)); + testConversion(false, " 0. ", DdCoordinate.valueOf(false, 0, null)); + + + testConversion(true, "- .4 ", DdCoordinate.valueOf(-0.4f)); + testConversion(true, " .4 ", DdCoordinate.valueOf(0.4f)); + testConversion(true, "- .04 ", DdCoordinate.valueOf(-0.04f)); + testConversion(true, " .04 ", DdCoordinate.valueOf(0.04f)); + testConversion(true, "- .004", DdCoordinate.valueOf(-0.004f)); + testConversion(true, " .004", DdCoordinate.valueOf(0.004f)); + testConversion(true, "- .044", DdCoordinate.valueOf(-0.044f)); + testConversion(true, " .044", DdCoordinate.valueOf(0.044f)); + testConversion(true, "- .444", DdCoordinate.valueOf(-0.444f)); + testConversion(true, " .444", DdCoordinate.valueOf(0.444f)); + testConversion(true, " .099", DdCoordinate.valueOf(false, null, 99)); + testConversion(true, " . ", DdCoordinate.empty()); + testConversion(true, " .099", DdCoordinate.valueOf(false, null, 99)); + testConversion(true, " 39.099", DdCoordinate.valueOf(false, 39, 99)); + testConversion(true, " 0. ", DdCoordinate.valueOf(false, 0, null)); + + } + + protected void testConversion(boolean forLongitude, String expectedString, DdCoordinate expectedCoordinate) { + + DdCoordinateConverter converter = (DdCoordinateConverter) ConverterUtil.getConverter(DdCoordinate.class); + Assert.assertNotNull(converter); + converter.setForLongitude(forLongitude); + + String actualStr; + DdCoordinate actualCoordinate; + + // String -> DdCoordinate + + actualCoordinate = converter.convert(DdCoordinate.class, expectedString); + Assert.assertNotNull(actualCoordinate); + Assert.assertEquals(actualCoordinate.isSign(), expectedCoordinate.isSign()); + Assert.assertEquals(actualCoordinate.getDegree(), expectedCoordinate.getDegree()); + Assert.assertEquals(actualCoordinate.getDecimal(), expectedCoordinate.getDecimal()); + + // DdCoordinate -> String + + actualStr = converter.convert(String.class, expectedCoordinate); + + Assert.assertNotNull(actualStr); + Assert.assertEquals(expectedString, actualStr); + + // String -> String + + actualStr = converter.convert(String.class, expectedString); + + Assert.assertNotNull(actualStr); + Assert.assertEquals(expectedString, actualStr); + + // DdCoordinate -> DdCoordinate + + actualCoordinate = converter.convert(DdCoordinate.class, expectedCoordinate); + Assert.assertNotNull(actualCoordinate); + Assert.assertEquals(actualCoordinate.isSign(), expectedCoordinate.isSign()); + Assert.assertEquals(actualCoordinate.getDegree(), expectedCoordinate.getDegree()); + Assert.assertEquals(actualCoordinate.getDecimal(), expectedCoordinate.getDecimal()); + } +} diff --git a/jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets/gis/DdCoordinateTest.java b/jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets/gis/DdCoordinateTest.java new file mode 100644 index 0000000..2e74dd8 --- /dev/null +++ b/jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets/gis/DdCoordinateTest.java @@ -0,0 +1,108 @@ +package org.nuiton.jaxx.widgets.gis; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Created on 9/2/14. + * + * @author Tony Chemit - chemit@codelutin.com + * @since XXX + */ +public class DdCoordinateTest { + + @Test + public void testFromDecimal() throws Exception { + + { + DdCoordinate coordinate = DdCoordinate.empty(); + + coordinate.fromDecimal(42.7f); + + assertDdCoordinate(coordinate, false, 42, 700); + + coordinate.addTrailingZero(); + + assertDdCoordinate(coordinate, false, 42, 700); + + coordinate.removeTrailingZero(); + + assertDdCoordinate(coordinate, false, 42, 700); + } + + { + DdCoordinate coordinate = DdCoordinate.empty(); + + float decimalExcepted = 42.707f; + coordinate.fromDecimal(decimalExcepted); + + assertDdCoordinate(coordinate, false, 42, 707); + + Float decimal = coordinate.toDecimal(); + Assert.assertEquals(decimalExcepted, decimal, 0.001); + } + } + + @Test + public void testToDecimal() throws Exception { + + { + DdCoordinate coordinate = DdCoordinate.empty(); + coordinate.setDegree(42); + coordinate.setDecimal(42); + Float actual = coordinate.toDecimal(); + Float expected = 42.042f; + Assert.assertEquals(expected, actual, 0.001); + } + + { + DdCoordinate coordinate = DdCoordinate.empty(); + coordinate.setDegree(12); + coordinate.setDecimal(2); + Float actual = coordinate.toDecimal(); + Float expected = 12.002f; + Assert.assertEquals(expected, actual, 0.0001); + + coordinate.fromDecimal(expected); + + assertDdCoordinate(coordinate, false, 12, 2); + } + + { + DdCoordinate component = DdCoordinate.empty(); + component.setDegree(12); + component.setDecimal(20); + Float actual = component.toDecimal(); + Float expected = 12.020f; + Assert.assertEquals(expected, actual, 0.001); + + component.fromDecimal(expected); + + assertDdCoordinate(component, false, 12, 20); + + } + } + + @Test + public void testValueOf() throws Exception { + + DdCoordinate coordinate = DdCoordinate.valueOf(-0.007333f); + Assert.assertNotNull(coordinate); + Assert.assertTrue(coordinate.isDegreeNull()); + + Assert.assertTrue(coordinate.isDegreeValid(true)); + Assert.assertTrue(coordinate.isDecimalValid()); + + assertDdCoordinate(coordinate, true, null, 7); + } + + public static void assertDdCoordinate(DdCoordinate coordinate, + boolean expectedSign, + Integer expectedDegree, + Integer expectedDecimal) { + Assert.assertNotNull(coordinate); + Assert.assertEquals(expectedSign, coordinate.isSign()); + Assert.assertEquals(expectedDegree, coordinate.getDegree()); + Assert.assertEquals(expectedDecimal, coordinate.getDecimal()); + } +} diff --git a/jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets/gis/DmdCoordinateConverterTest.java b/jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets/gis/DmdCoordinateConverterTest.java new file mode 100644 index 0000000..77e015d --- /dev/null +++ b/jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets/gis/DmdCoordinateConverterTest.java @@ -0,0 +1,102 @@ +package org.nuiton.jaxx.widgets.gis; + +/* + * #%L + * JAXX :: Widgets + * %% + * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.junit.Assert; +import org.junit.Test; +import org.nuiton.converter.ConverterUtil; + +/** + * Created on 11/25/13. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 2.6 + */ +public class DmdCoordinateConverterTest { + + @Test + public void testConvert() throws Exception { + + ConverterUtil.initConverters(); + + testConversion(false, "- ° '44", DmdCoordinate.valueOf(-0.007333f)); + testConversion(false, " ° '44", DmdCoordinate.valueOf(0.007333f)); + testConversion(false, " ° '99", DmdCoordinate.valueOf(false, null, null, 99)); + testConversion(false, " ° ' ", DmdCoordinate.empty()); + testConversion(false, " °39'99", DmdCoordinate.valueOf(false, null, 39, 99)); + testConversion(false, " °39' ", DmdCoordinate.valueOf(false, null, 39, null)); + testConversion(false, " 0°39'99", DmdCoordinate.valueOf(false, 0, 39, 99)); + testConversion(false, " 0° ' ", DmdCoordinate.valueOf(false, 0, null, null)); + + testConversion(true, "- ° '44", DmdCoordinate.valueOf(-0.007333f)); + testConversion(true, " ° '44", DmdCoordinate.valueOf(0.007333f)); + testConversion(true, " ° ' ", DmdCoordinate.empty()); + testConversion(true, " ° '99", DmdCoordinate.valueOf(false, null, null, 99)); + testConversion(true, " °39'99", DmdCoordinate.valueOf(false, null, 39, 99)); + testConversion(true, " °39' ", DmdCoordinate.valueOf(false, null, 39, null)); + testConversion(true, " 0°39'99", DmdCoordinate.valueOf(false, 0, 39, 99)); + testConversion(true, " 0° ' ", DmdCoordinate.valueOf(false, 0, null, null)); + } + + protected void testConversion(boolean forLongitude, String expectedString, DmdCoordinate expectedCoordinate) { + + DmdCoordinateConverter converter = (DmdCoordinateConverter) ConverterUtil.getConverter(DmdCoordinate.class); + converter.setForLongitude(forLongitude); + Assert.assertNotNull(converter); + + String actualStr; + DmdCoordinate actualCoordinate; + + // String -> DmdCoordinate + + actualCoordinate = converter.convert(DmdCoordinate.class, expectedString); + Assert.assertNotNull(actualCoordinate); + Assert.assertEquals(actualCoordinate.isSign(), expectedCoordinate.isSign()); + Assert.assertEquals(actualCoordinate.getDegree(), expectedCoordinate.getDegree()); + Assert.assertEquals(actualCoordinate.getMinute(), expectedCoordinate.getMinute()); + Assert.assertEquals(actualCoordinate.getDecimal(), expectedCoordinate.getDecimal()); + + // DmdCoordinate -> String + + actualStr = converter.convert(String.class, expectedCoordinate); + + Assert.assertNotNull(actualStr); + Assert.assertEquals(expectedString, actualStr); + + // String -> String + + actualStr = converter.convert(String.class, expectedString); + + Assert.assertNotNull(actualStr); + Assert.assertEquals(expectedString, actualStr); + + // DmdCoordinate -> DmdCoordinate + + actualCoordinate = converter.convert(DmdCoordinate.class, expectedCoordinate); + Assert.assertNotNull(actualCoordinate); + Assert.assertEquals(actualCoordinate.isSign(), expectedCoordinate.isSign()); + Assert.assertEquals(actualCoordinate.getDegree(), expectedCoordinate.getDegree()); + Assert.assertEquals(actualCoordinate.getMinute(), expectedCoordinate.getMinute()); + Assert.assertEquals(actualCoordinate.getDecimal(), expectedCoordinate.getDecimal()); + } +} diff --git a/jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets/gis/DmdCoordinateTest.java b/jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets/gis/DmdCoordinateTest.java new file mode 100644 index 0000000..0e22e73 --- /dev/null +++ b/jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets/gis/DmdCoordinateTest.java @@ -0,0 +1,136 @@ +package org.nuiton.jaxx.widgets.gis; + +/* + * #%L + * JAXX :: Widgets + * %% + * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.junit.Assert; +import org.junit.Test; + +/** + * Created on 10/25/13. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 2.6 + */ +public class DmdCoordinateTest { + + @Test + public void testFromDecimal() throws Exception { + + { + DmdCoordinate coordinate = DmdCoordinate.empty(); + + coordinate.fromDecimal(42.7f); + + assertDmdCoordinate(coordinate, false, 42, 42, null); + + coordinate.addTrailingZero(); + + assertDmdCoordinate(coordinate, false, 42, 42, 0); + + coordinate.removeTrailingZero(); + + assertDmdCoordinate(coordinate, false, 42, 42, null); + } + + { + DmdCoordinate coordinate = DmdCoordinate.empty(); + + float decimalExcepted = 42.707f; + coordinate.fromDecimal(decimalExcepted); + + assertDmdCoordinate(coordinate, false, 42, 42, 42); + + Float decimal = coordinate.toDecimal(); + Assert.assertEquals(decimalExcepted, decimal, 0.001); + } + } + + @Test + public void testToDecimal() throws Exception { + + { + DmdCoordinate coordinate = DmdCoordinate.empty(); + coordinate.setDegree(42); + coordinate.setMinute(42); + coordinate.setDecimal(42); + Float actual = coordinate.toDecimal(); + Float expected = 42.707f; + Assert.assertEquals(expected, actual, 0.001); + } + + { + DmdCoordinate coordinate = DmdCoordinate.empty(); + coordinate.setDegree(12); + coordinate.setMinute(12); + Float actual = coordinate.toDecimal(); + Float expected = 12.2f; + Assert.assertEquals(expected, actual, 0.0001); + + coordinate.fromDecimal(expected); + + assertDmdCoordinate(coordinate, false, 12, 12, null); + } + + { + DmdCoordinate component = DmdCoordinate.empty(); + component.setDegree(12); + component.setMinute(12); + component.setDecimal(20); + Float actual = component.toDecimal(); + Float expected = 12.203333f; + Assert.assertEquals(expected, actual, 0.001); + + component.fromDecimal(expected); + + assertDmdCoordinate(component, false, 12, 12, 20); + + } + } + + @Test + public void testValueOf() throws Exception { + + DmdCoordinate coordinate = DmdCoordinate.valueOf(-0.007333f); + Assert.assertNotNull(coordinate); + Assert.assertTrue(coordinate.isDegreeNull()); + Assert.assertTrue(coordinate.isMinuteNull()); + + Assert.assertTrue(coordinate.isDegreeValid(true)); + Assert.assertTrue(coordinate.isMinuteValid()); + Assert.assertTrue(coordinate.isDecimalValid()); + + assertDmdCoordinate(coordinate, true, null, null, 44); + } + + public static void assertDmdCoordinate(DmdCoordinate coordinate, + boolean expectedSign, + Integer expectedDegree, + Integer expectedMinute, + Integer expectedDecimal) { + Assert.assertNotNull(coordinate); + Assert.assertEquals(expectedSign, coordinate.isSign()); + Assert.assertEquals(expectedDegree, coordinate.getDegree()); + Assert.assertEquals(expectedMinute, coordinate.getMinute()); + Assert.assertEquals(expectedDecimal, coordinate.getDecimal()); + } +} diff --git a/jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets/gis/DmsCoordinateConverterTest.java b/jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets/gis/DmsCoordinateConverterTest.java new file mode 100644 index 0000000..d4c8f09 --- /dev/null +++ b/jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets/gis/DmsCoordinateConverterTest.java @@ -0,0 +1,105 @@ +package org.nuiton.jaxx.widgets.gis; + +/* + * #%L + * JAXX :: Widgets + * %% + * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.junit.Assert; +import org.junit.Test; +import org.nuiton.converter.ConverterUtil; + +/** + * Created on 11/25/13. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 2.6 + */ +public class DmsCoordinateConverterTest { + + + @Test + public void testConvert() throws Exception { + + ConverterUtil.initConverters(); + + testConversion(false, "- ° '26''", DmsCoordinate.valueOf(-0.007333f)); + testConversion(false, " ° '26''", DmsCoordinate.valueOf(0.007333f)); + testConversion(false, " ° '59''", DmsCoordinate.valueOf(false, null, null, 59)); + testConversion(false, " ° ' ''", DmsCoordinate.empty()); + testConversion(false, " °39'59''", DmsCoordinate.valueOf(false, null, 39, 59)); + testConversion(false, " °39' ''", DmsCoordinate.valueOf(false, null, 39, null)); + testConversion(false, " 0°39'59''", DmsCoordinate.valueOf(false, 0, 39, 59)); + testConversion(false, " 0° ' ''", DmsCoordinate.valueOf(false, 0, null, null)); + + testConversion(true, "- ° '26''", DmsCoordinate.valueOf(-0.007333f)); + testConversion(true, " ° '26''", DmsCoordinate.valueOf(0.007333f)); + testConversion(true, " ° ' ''", DmsCoordinate.empty()); + testConversion(true, " ° '59''", DmsCoordinate.valueOf(false, null, null, 59)); + testConversion(true, " °39'59''", DmsCoordinate.valueOf(false, null, 39, 59)); + testConversion(true, " °39' ''", DmsCoordinate.valueOf(false, null, 39, null)); + testConversion(true, " 0°39'59''", DmsCoordinate.valueOf(false, 0, 39, 59)); + testConversion(true, " 0° ' ''", DmsCoordinate.valueOf(false, 0, null, null)); + } + + protected void testConversion(boolean forLongitude, + String expectedString, + DmsCoordinate expectedCoordinate) { + + DmsCoordinateConverter converter = (DmsCoordinateConverter) ConverterUtil.getConverter(DmsCoordinate.class); + converter.setForLongitude(forLongitude); + Assert.assertNotNull(converter); + + String actualStr; + DmsCoordinate actualCoordinate; + + // String -> DmsCoordinate + + actualCoordinate = (DmsCoordinate) converter.convert(DmsCoordinate.class, expectedString); + Assert.assertNotNull(actualCoordinate); + Assert.assertEquals(actualCoordinate.isSign(), expectedCoordinate.isSign()); + Assert.assertEquals(actualCoordinate.getDegree(), expectedCoordinate.getDegree()); + Assert.assertEquals(actualCoordinate.getMinute(), expectedCoordinate.getMinute()); + Assert.assertEquals(actualCoordinate.getSecond(), expectedCoordinate.getSecond()); + + // DmsCoordinate -> String + + actualStr = (String) converter.convert(String.class, expectedCoordinate); + + Assert.assertNotNull(actualStr); + Assert.assertEquals(expectedString, actualStr); + + // String -> String + + actualStr = (String) converter.convert(String.class, expectedString); + + Assert.assertNotNull(actualStr); + Assert.assertEquals(expectedString, actualStr); + + // DmsCoordinate -> DmsCoordinate + + actualCoordinate = (DmsCoordinate) converter.convert(DmsCoordinate.class, expectedCoordinate); + Assert.assertNotNull(actualCoordinate); + Assert.assertEquals(actualCoordinate.isSign(), expectedCoordinate.isSign()); + Assert.assertEquals(actualCoordinate.getDegree(), expectedCoordinate.getDegree()); + Assert.assertEquals(actualCoordinate.getMinute(), expectedCoordinate.getMinute()); + Assert.assertEquals(actualCoordinate.getSecond(), expectedCoordinate.getSecond()); + } +} diff --git a/jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets/gis/DmsCoordinateTest.java b/jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets/gis/DmsCoordinateTest.java new file mode 100644 index 0000000..53276db --- /dev/null +++ b/jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets/gis/DmsCoordinateTest.java @@ -0,0 +1,131 @@ +package org.nuiton.jaxx.widgets.gis; + +/* + * #%L + * JAXX :: Widgets + * %% + * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.junit.Assert; +import org.junit.Test; + +/** + * Created on 11/25/13. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 2.6 + */ +public class DmsCoordinateTest { + + @Test + public void testFromDecimal() throws Exception { + + { + DmsCoordinate actual = DmsCoordinate.empty(); + + actual.fromDecimal(42.7f); + + assertDmsCoordinate(actual, false, 42, 42, null); + } + + { + DmsCoordinate actual = DmsCoordinate.empty(); + + float decimalExcepted = 42.711f; + actual.fromDecimal(decimalExcepted); + + assertDmsCoordinate(actual, false, 42, 42, 39); + + Float decimal = actual.toDecimal(); + Assert.assertEquals(decimalExcepted, decimal, 0.001); + } + } + + @Test + public void testToDecimal() throws Exception { + + { + DmsCoordinate coordinate = DmsCoordinate.empty(); + coordinate.setDegree(42); + coordinate.setMinute(42); + coordinate.setSecond(42); + Float floatValue = coordinate.toDecimal(); + Float expected = 42.712f; + Assert.assertEquals(expected, floatValue, 0.001); + } + + { + DmsCoordinate coordinate = DmsCoordinate.empty(); + coordinate.setDegree(12); + coordinate.setMinute(12); + + Float floatValue = coordinate.toDecimal(); + Float expected = 12.2001f; + Assert.assertEquals(expected, floatValue, 0.001); + + coordinate.fromDecimal(expected); + assertDmsCoordinate(coordinate, false, 12, 12, null); + + } + + { + DmsCoordinate coordinate = DmsCoordinate.empty(); + coordinate.setDegree(12); + coordinate.setMinute(12); + coordinate.setSecond(20); + Float floatValue = coordinate.toDecimal(); + Float expected = 12.20569f; + Assert.assertEquals(expected, floatValue, 0.001); + + coordinate.fromDecimal(expected); + + assertDmsCoordinate(coordinate, false, 12, 12, 20); + } + } + + + @Test + public void testValueOf() throws Exception { + + DmsCoordinate coordinate = DmsCoordinate.valueOf(-0.007333f); + Assert.assertNotNull(coordinate); + Assert.assertTrue(coordinate.isDegreeNull()); + Assert.assertTrue(coordinate.isMinuteNull()); + Assert.assertFalse(coordinate.isSecondNull()); + + + Assert.assertTrue(coordinate.isDegreeValid(true)); + Assert.assertTrue(coordinate.isMinuteValid()); + Assert.assertTrue(coordinate.isSecondValid()); + + assertDmsCoordinate(coordinate, true, null, null, 26); + } + + public static void assertDmsCoordinate(DmsCoordinate coordinate, + boolean expectedSign, + Integer expectedDegree, + Integer expectedMinute, + Integer expectedSecond) { + Assert.assertNotNull(coordinate); + Assert.assertEquals(expectedSign, coordinate.isSign()); + Assert.assertEquals(expectedDegree, coordinate.getDegree()); + Assert.assertEquals(expectedMinute, coordinate.getMinute()); + Assert.assertEquals(expectedSecond, coordinate.getSecond()); + } +} diff --git a/jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmdCoordinateEditorTest.java b/jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmdCoordinateEditorTest.java new file mode 100644 index 0000000..c15995e --- /dev/null +++ b/jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmdCoordinateEditorTest.java @@ -0,0 +1,213 @@ +package org.nuiton.jaxx.widgets.gis.signed; + +/* + * #%L + * JAXX :: Widgets + * %% + * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jdesktop.beans.AbstractSerializableBean; +import org.nuiton.jaxx.widgets.gis.DmdCoordinate; + +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; +import javax.swing.border.TitledBorder; +import java.awt.BorderLayout; +import java.awt.GridLayout; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.text.ParseException; + +/** + * To test the {@link SignedDmsCoordinateEditor}. + * <p/> + * Created on 10/17/13. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 2.6 + */ +public class SignedDmdCoordinateEditorTest { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(SignedDmdCoordinateEditorTest.class); + + public static class EditorBean extends AbstractSerializableBean { + + private static final long serialVersionUID = 1L; + + public static final String PROPERTY_LONGITUDE_SIGN = "longitudeSign"; + + public static final String PROPERTY_LONGITUDE_DEGREE = "longitudeDegree"; + + public static final String PROPERTY_LONGITUDE_MINUTE = "longitudeMinute"; + + public static final String PROPERTY_LONGITUDE_DECIMAL = "longitudeDecimal"; + + public static final String PROPERTY_LATITUDE_SIGN = "latitudeSign"; + + public static final String PROPERTY_LATITUDE_DEGREE = "latitudeDegree"; + + public static final String PROPERTY_LATITUDE_MINUTE = "latitudeMinute"; + + public static final String PROPERTY_LATITUDE_DECIMAL = "latitudeDecimal"; + + protected final DmdCoordinate longitude = DmdCoordinate.empty(); + + protected final DmdCoordinate latitude = DmdCoordinate.empty(); + + public DmdCoordinate getLongitude() { + return longitude; + } + + public void setLongitudeDegree(Integer degre) { + Object oldValue = longitude.getDegree(); + longitude.setDegree(degre); + firePropertyChange(PROPERTY_LONGITUDE_DEGREE, oldValue, degre); + } + + public void setLongitudeMinute(Integer minute) { + Object oldValue = longitude.getMinute(); + longitude.setMinute(minute); + firePropertyChange(PROPERTY_LONGITUDE_MINUTE, oldValue, minute); + } + + public void setLongitudeDecimal(Integer decimal) { + Object oldValue = longitude.getDecimal(); + longitude.setDecimal(decimal); + firePropertyChange(PROPERTY_LONGITUDE_DECIMAL, oldValue, decimal); + } + + public void setLongitudeSign(boolean sign) { + Object oldValue = longitude.isSign(); + longitude.setSign(sign); + firePropertyChange(PROPERTY_LONGITUDE_SIGN, oldValue, sign); + } + + public DmdCoordinate getLatitude() { + return latitude; + } + + public void setLatitudeSign(boolean sign) { + Object oldValue = latitude.isSign(); + latitude.setSign(sign); + firePropertyChange(PROPERTY_LATITUDE_SIGN, oldValue, sign); + } + + public void setLatitudeDegree(Integer degre) { + Object oldValue = latitude.getDegree(); + latitude.setDegree(degre); + firePropertyChange(PROPERTY_LATITUDE_DEGREE, oldValue, degre); + } + + public void setLatitudeMinute(Integer minute) { + Object oldValue = latitude.getMinute(); + latitude.setMinute(minute); + firePropertyChange(PROPERTY_LATITUDE_MINUTE, oldValue, minute); + } + + public void setLatitudeDecimal(Integer decimal) { + Object oldValue = latitude.getDecimal(); + latitude.setDecimal(decimal); + firePropertyChange(PROPERTY_LATITUDE_DECIMAL, oldValue, decimal); + } + + @Override + public String toString() { + return "EditorBean{" + + "longitude=" + longitude + + ", latitude=" + latitude + + '}'; + } + } + + public static void main(String[] args) throws ParseException { + + + EditorBean bean = new EditorBean(); + + SignedDmdCoordinateEditor longitudeEditor = new SignedDmdCoordinateEditor(); + longitudeEditor.setBean(bean); + longitudeEditor.setPropertySign(EditorBean.PROPERTY_LONGITUDE_SIGN); + longitudeEditor.setPropertyDegree(EditorBean.PROPERTY_LONGITUDE_DEGREE); + longitudeEditor.setPropertyMinute(EditorBean.PROPERTY_LONGITUDE_MINUTE); + longitudeEditor.setPropertyDecimal(EditorBean.PROPERTY_LONGITUDE_DECIMAL); + longitudeEditor.setShowReset(true); + longitudeEditor.init(true); + + SignedDmdCoordinateEditor latitudeEditor = new SignedDmdCoordinateEditor(); + latitudeEditor.setBean(bean); + latitudeEditor.setPropertySign(EditorBean.PROPERTY_LATITUDE_SIGN); + latitudeEditor.setPropertyDegree(EditorBean.PROPERTY_LATITUDE_DEGREE); + latitudeEditor.setPropertyMinute(EditorBean.PROPERTY_LATITUDE_MINUTE); + latitudeEditor.setPropertyDecimal(EditorBean.PROPERTY_LATITUDE_DECIMAL); + latitudeEditor.setShowReset(true); + latitudeEditor.init(false); + + final JLabel latitudeResult = new JLabel(); + final JLabel longitudeResult = new JLabel(); + + bean.addPropertyChangeListener(new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + EditorBean source = (EditorBean) evt.getSource(); + String propertyName = evt.getPropertyName(); + if (log.isInfoEnabled()) { + log.info("[" + propertyName + "] value changed: " + evt.getNewValue()); + } + if (propertyName.startsWith("longitude")) { + longitudeResult.setText(source.getLongitude().toString()); + } else { + + latitudeResult.setText(source.getLatitude().toString()); + } + } + }); + + JPanel longitudeEditorPanel = new JPanel(new GridLayout()); + longitudeEditorPanel.setBorder(new TitledBorder("Longitude")); + longitudeEditorPanel.add(BorderLayout.CENTER, longitudeEditor); + longitudeEditorPanel.add(BorderLayout.EAST, longitudeResult); + + JPanel latitudeEditorPanel = new JPanel(new GridLayout()); + latitudeEditorPanel.setBorder(new TitledBorder("Latitude")); + latitudeEditorPanel.add(BorderLayout.CENTER, latitudeEditor); + latitudeEditorPanel.add(BorderLayout.EAST, latitudeResult); + + JPanel panel = new JPanel(new GridLayout(0, 1)); + panel.add(longitudeEditorPanel); + panel.add(latitudeEditorPanel); + + final JDialog frame = new JDialog(); + + frame.setContentPane(panel); + + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + frame.setSize(800, 200); + frame.setVisible(true); + } + }); + } +} diff --git a/jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmsCoordinateEditorTest.java b/jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmsCoordinateEditorTest.java new file mode 100644 index 0000000..103800e --- /dev/null +++ b/jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets/gis/signed/SignedDmsCoordinateEditorTest.java @@ -0,0 +1,215 @@ +package org.nuiton.jaxx.widgets.gis.signed; + +/* + * #%L + * JAXX :: Widgets + * %% + * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jdesktop.beans.AbstractSerializableBean; +import org.nuiton.jaxx.widgets.gis.DmsCoordinate; + +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; +import javax.swing.border.TitledBorder; +import java.awt.BorderLayout; +import java.awt.GridLayout; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.text.ParseException; + +/** + * To test the {@link SignedDmsCoordinateEditor}. + * <p/> + * Created on 10/17/13. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 2.6 + */ +public class SignedDmsCoordinateEditorTest { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(SignedDmsCoordinateEditorTest.class); + + public static class EditorBean extends AbstractSerializableBean { + + private static final long serialVersionUID = 1L; + + public static final String PROPERTY_LONGITUDE_SIGN = "longitudeSign"; + + public static final String PROPERTY_LONGITUDE_DEGREE = "longitudeDegree"; + + public static final String PROPERTY_LONGITUDE_MINUTE = "longitudeMinute"; + + public static final String PROPERTY_LONGITUDE_SECOND = "longitudeSecond"; + + public static final String PROPERTY_LATITUDE_SIGN = "latitudeSign"; + + public static final String PROPERTY_LATITUDE_DEGREE = "latitudeDegree"; + + public static final String PROPERTY_LATITUDE_MINUTE = "latitudeMinute"; + + public static final String PROPERTY_LATITUDE_SECOND = "latitudeSecond"; + + protected final DmsCoordinate longitude = DmsCoordinate.empty(); + + protected final DmsCoordinate latitude = DmsCoordinate.empty(); + + public DmsCoordinate getLongitude() { + return longitude; + } + + public void setLongitudeDegree(Integer degre) { + Object oldValue = longitude.getDegree(); + longitude.setDegree(degre); + firePropertyChange(PROPERTY_LONGITUDE_DEGREE, oldValue, degre); + } + + public void setLongitudeMinute(Integer minute) { + Object oldValue = longitude.getMinute(); + longitude.setMinute(minute); + firePropertyChange(PROPERTY_LONGITUDE_MINUTE, oldValue, minute); + } + + public void setLongitudeSecond(Integer seconde) { + Object oldValue = longitude.getSecond(); + + longitude.setSecond(seconde); + firePropertyChange(PROPERTY_LONGITUDE_SECOND, oldValue, seconde); + } + + public void setLongitudeSign(boolean sign) { + Object oldValue = longitude.isSign(); + longitude.setSign(sign); + firePropertyChange(PROPERTY_LONGITUDE_SIGN, oldValue, sign); + } + + public DmsCoordinate getLatitude() { + return latitude; + } + + public void setLatitudeDegree(Integer degre) { + Object oldValue = latitude.getDegree(); + latitude.setDegree(degre); + firePropertyChange(PROPERTY_LATITUDE_DEGREE, oldValue, degre); + } + + public void setLatitudeMinute(Integer minute) { + Object oldValue = latitude.getMinute(); + latitude.setMinute(minute); + firePropertyChange(PROPERTY_LATITUDE_MINUTE, oldValue, minute); + } + + + public void setLatitudeSecond(Integer seconde) { + Object oldValue = latitude.getSecond(); + latitude.setSecond(seconde); + firePropertyChange(PROPERTY_LATITUDE_SECOND, oldValue, seconde); + } + + public void setLatitudeSign(boolean sign) { + Object oldValue = latitude.isSign(); + latitude.setSign(sign); + firePropertyChange(PROPERTY_LATITUDE_SIGN, oldValue, sign); + } + + @Override + public String toString() { + return "EditorBean{" + + "longitude=" + longitude + + ", latitude=" + latitude + + '}'; + } + } + + public static void main(String[] args) throws ParseException { + + + EditorBean bean = new EditorBean(); + + SignedDmsCoordinateEditor longitudeEditor = new SignedDmsCoordinateEditor(); + longitudeEditor.setBean(bean); + longitudeEditor.setPropertySign(EditorBean.PROPERTY_LONGITUDE_SIGN); + longitudeEditor.setPropertyDegree(EditorBean.PROPERTY_LONGITUDE_DEGREE); + longitudeEditor.setPropertyMinute(EditorBean.PROPERTY_LONGITUDE_MINUTE); + longitudeEditor.setPropertySecond(EditorBean.PROPERTY_LONGITUDE_SECOND); + longitudeEditor.setShowReset(true); + longitudeEditor.init(true); + + SignedDmsCoordinateEditor latitudeEditor = new SignedDmsCoordinateEditor(); + latitudeEditor.setBean(bean); + latitudeEditor.setPropertySign(EditorBean.PROPERTY_LATITUDE_SIGN); + latitudeEditor.setPropertyDegree(EditorBean.PROPERTY_LATITUDE_DEGREE); + latitudeEditor.setPropertyMinute(EditorBean.PROPERTY_LATITUDE_MINUTE); + latitudeEditor.setPropertySecond(EditorBean.PROPERTY_LATITUDE_SECOND); + latitudeEditor.setShowReset(true); + latitudeEditor.init(false); + + final JLabel latitudeResult = new JLabel(); + final JLabel longitudeResult = new JLabel(); + + bean.addPropertyChangeListener(new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + EditorBean source = (EditorBean) evt.getSource(); + String propertyName = evt.getPropertyName(); + if (log.isInfoEnabled()) { + log.info("[" + propertyName + "] value changed: " + evt.getNewValue()); + } + if (propertyName.startsWith("longitude")) { + longitudeResult.setText(source.getLongitude().toString()); + } else { + + latitudeResult.setText(source.getLatitude().toString()); + } + } + }); + + JPanel longitudeEditorPanel = new JPanel(new GridLayout()); + longitudeEditorPanel.setBorder(new TitledBorder("Longitude")); + longitudeEditorPanel.add(BorderLayout.CENTER, longitudeEditor); + longitudeEditorPanel.add(BorderLayout.EAST, longitudeResult); + + JPanel latitudeEditorPanel = new JPanel(new GridLayout()); + latitudeEditorPanel.setBorder(new TitledBorder("Latitude")); + latitudeEditorPanel.add(BorderLayout.CENTER, latitudeEditor); + latitudeEditorPanel.add(BorderLayout.EAST, latitudeResult); + + JPanel panel = new JPanel(new GridLayout(0, 1)); + panel.add(longitudeEditorPanel); + panel.add(latitudeEditorPanel); + + final JDialog frame = new JDialog(); + + frame.setContentPane(panel); + + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + frame.setSize(800, 200); + frame.setVisible(true); + } + }); + } +} diff --git a/jaxx-widgets-gis/src/test/resources/log4j.properties b/jaxx-widgets-gis/src/test/resources/log4j.properties new file mode 100644 index 0000000..a9515ea --- /dev/null +++ b/jaxx-widgets-gis/src/test/resources/log4j.properties @@ -0,0 +1,31 @@ +### +# #%L +# JAXX :: Widgets +# %% +# Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Lesser Public License for more details. +# +# You should have received a copy of the GNU General Lesser Public +# License along with this program. If not, see +# <http://www.gnu.org/licenses/lgpl-3.0.html>. +# #L% +### +# Global logging configuration +log4j.rootLogger=ERROR, stdout +# Console output... +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n + +log4j.logger.jaxx.runtime.swing=DEBUG +#log4j.logger.jaxx.runtime.swing.editor.config.model.ConfigUIModelBuilder=DEBUG +log4j.logger.org.nuiton=WARN diff --git a/pom.xml b/pom.xml index eaedb02..1d8b3a5 100644 --- a/pom.xml +++ b/pom.xml @@ -40,6 +40,7 @@ <module>jaxx-compiler</module> <module>jaxx-maven-plugin</module> <module>jaxx-widgets</module> + <module>jaxx-widgets-gis</module> <module>jaxx-config</module> <module>jaxx-application-api</module> <module>jaxx-application-swing</module> -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
participants (1)
-
nuiton.org scm