This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository jaxx. See https://gitlab.nuiton.org/nuiton/jaxx.git commit 5bd62db7890aada615519b35fbc81664600914e8 Author: Tony CHEMIT <dev@tchemit.fr> Date: Sat Dec 31 13:06:27 2016 +0100 removing deprecated widgets (See #4103) --- .../component/jaxx/editor/NumberEditorDemo.jaxx | 113 ---- .../jaxx/editor/NumberEditorDemoModel.java | 62 --- .../jaxx/editor/SimpleTimeEditorDemo.jaxx | 81 --- .../jaxx/editor/SimpleTimeEditorDemo.jcss | 37 -- .../jaxx/editor/SimpleTimeEditorDemoHandler.java | 47 -- .../jaxx/editor/SimpleTimeEditorDemoModel.java | 54 -- .../demo/component/jaxx/editor/TimeEditorDemo.jaxx | 84 --- .../demo/component/jaxx/editor/TimeEditorDemo.jcss | 47 -- .../component/jaxx/editor/TimeEditorDemoModel.java | 53 -- .../component/jaxx/editor/gis/CoordinateDemo.jaxx | 97 ---- .../component/jaxx/editor/gis/CoordinateDemo.jcss | 146 ----- .../jaxx/editor/gis/CoordinateDemoHandler.java | 154 ------ .../jaxx/editor/gis/CoordinateDemoModel.java | 64 --- .../nuiton/jaxx/demo/tree/DemoDataProvider.java | 10 +- .../jaxx/runtime/swing/editor/KeyStrokeEditor.java | 14 +- .../jaxx/runtime/swing/editor/NumberEditor.jaxx | 205 ------- .../runtime/swing/editor/NumberEditorHandler.java | 591 --------------------- .../runtime/swing/editor/NumberEditorPopup.jcss | 47 -- .../runtime/swing/editor/SimpleTimeEditor.jaxx | 61 --- .../runtime/swing/editor/SimpleTimeEditor.jcss | 42 -- .../swing/editor/SimpleTimeEditorHandler.java | 283 ---------- .../swing/editor/SimpleTimeEditorModel.java | 109 ---- .../jaxx/runtime/swing/editor/TimeEditor.jaxx | 87 --- .../jaxx/runtime/swing/editor/TimeEditor.jcss | 58 -- .../runtime/swing/editor/TimeEditorHandler.java | 319 ----------- .../runtime/swing/editor/gis/DmdCoordinate.java | 336 ------------ .../swing/editor/gis/DmdCoordinateConverter.java | 143 ----- .../swing/editor/gis/DmdCoordinateEditor.jaxx | 58 -- .../swing/editor/gis/DmdCoordinateEditor.jcss | 38 -- .../editor/gis/DmdCoordinateEditorHandler.java | 303 ----------- .../swing/editor/gis/DmdCoordinateEditorModel.java | 122 ----- .../runtime/swing/editor/gis/DmsCoordinate.java | 364 ------------- .../swing/editor/gis/DmsCoordinateConverter.java | 144 ----- .../swing/editor/gis/DmsCoordinateEditor.jaxx | 59 -- .../swing/editor/gis/DmsCoordinateEditor.jcss | 38 -- .../editor/gis/DmsCoordinateEditorHandler.java | 314 ----------- .../swing/editor/gis/DmsCoordinateEditorModel.java | 122 ----- .../editor/gis/MaskFormatterFromConverter.java | 75 --- .../services/org.nuiton.converter.NuitonConverter | 2 - .../editor/gis/DmdCoordinateConverterTest.java | 102 ---- .../swing/editor/gis/DmdCoordinateEditorTest.java | 204 ------- .../swing/editor/gis/DmdCoordinateTest.java | 136 ----- .../editor/gis/DmsCoordinateConverterTest.java | 105 ---- .../swing/editor/gis/DmsCoordinateEditorTest.java | 206 ------- .../swing/editor/gis/DmsCoordinateTest.java | 131 ----- jaxx-widgets/src/test/resources/log4j.properties | 30 -- 46 files changed, 7 insertions(+), 5890 deletions(-) diff --git a/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/NumberEditorDemo.jaxx b/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/NumberEditorDemo.jaxx deleted file mode 100644 index 4063fef..0000000 --- a/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/NumberEditorDemo.jaxx +++ /dev/null @@ -1,113 +0,0 @@ -<!-- - #%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% - --> - -<org.nuiton.jaxx.demo.DemoPanel layout='{new BorderLayout()}'> - - <import> - org.nuiton.jaxx.runtime.swing.editor.NumberEditor - static org.nuiton.i18n.I18n.t - </import> - - <!-- model --> - <NumberEditorDemoModel id='demoModel'/> - - <script><![CDATA[ - -public void changeNumberPattern() { - editor.setNumberPattern(numberPattern.getText()); -} - -void $afterCompleteSetup() { - editor.init(); - changeNumberPattern(); -} - -]]> - </script> - - <Table insets='0' fill='both' weightx='1' constraints='BorderLayout.NORTH'> - <row> - <cell> - <JPanel - border='{new TitledBorder(t("jaxxdemo.numbereditor.configuration"))}' - layout='{new GridLayout(0,1)}'> - - <JCheckBox id='useFloat' - text='jaxxdemo.numbereditor.useFloat' - selected='true'/> - - <JCheckBox id='useSign' - text='jaxxdemo.numbereditor.useSign' - selected='true'/> - - <JCheckBox id='showPopupButton' - text='jaxxdemo.numbereditor.showPopupButton' - selected='true'/> - - <JCheckBox id='showResetButton' - text='jaxxdemo.numbereditor.showReset' - selected='true'/> - - <JCheckBox id='autoPopup' - text='jaxxdemo.numbereditor.autoPopup' - selected='false'/> - <JPanel - border='{new TitledBorder(t("jaxxdemo.numbereditor.numberPattern.configuration"))}' - layout='{new GridLayout(1,0)}'> - <JTextField id='numberPattern' text='{"\\d{0,3}"}'/> - <JButton id='applyNumberPattern' - text='jaxxdemo.numbereditor.applyNumberPattern' - onActionPerformed='changeNumberPattern();'/> - </JPanel> - </JPanel> - </cell> - </row> - <row> - <cell> - <org.nuiton.jaxx.runtime.swing.editor.NumberEditor id='editor' - constructorParams='this' - bean='{demoModel}' - property='{useFloat.isSelected() ? "floatProperty" : "integerProperty"}' - useFloat='{useFloat.isSelected()}' - useSign='{useSign.isSelected()}' - autoPopup='{autoPopup.isSelected()}' - showPopupButton='{showPopupButton.isSelected()}' - showReset='{showResetButton.isSelected()}'/> - </cell> - </row> - <row> - <cell> - <JPanel border='{new TitledBorder(t("jaxxdemo.numbereditor.model"))}' - layout='{new GridLayout(0,1)}'> - <JLabel - text='{t("jaxxdemo.numbereditor.model.numberPattern", editor.getNumberPattern())}'/> - <JLabel - text='{t("jaxxdemo.numbereditor.model.int", demoModel.getIntegerProperty())}'/> - <JLabel - text='{t("jaxxdemo.numbereditor.model.float", demoModel.getFloatProperty())}'/> - - </JPanel> - </cell> - </row> - </Table> -</org.nuiton.jaxx.demo.DemoPanel> - diff --git a/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/NumberEditorDemoModel.java b/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/NumberEditorDemoModel.java deleted file mode 100644 index 86f729e..0000000 --- a/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/NumberEditorDemoModel.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * #%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% - */ - -package org.nuiton.jaxx.demo.component.jaxx.editor; - -import org.jdesktop.beans.AbstractSerializableBean; - -/** - * @author Tony Chemit - dev@tchemit.fr - * @since 1.5 - */ -public class NumberEditorDemoModel extends AbstractSerializableBean { - - public static final String INTEGER_PROPERTY = "integerProperty"; - - public static final String FLOAT_PROPERTY = "floatProperty"; - - private static final long serialVersionUID = 1L; - - protected int integerProperty; - - protected float floatProperty; - - public float getFloatProperty() { - return floatProperty; - } - - public int getIntegerProperty() { - return integerProperty; - } - - public void setFloatProperty(float floatProperty) { - float old = this.floatProperty; - this.floatProperty = floatProperty; - firePropertyChange(FLOAT_PROPERTY, old, floatProperty); - } - - public void setIntegerProperty(int integerProperty) { - int old = this.integerProperty; - this.integerProperty = integerProperty; - firePropertyChange(INTEGER_PROPERTY, old, integerProperty); - } -} diff --git a/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemo.jaxx b/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemo.jaxx deleted file mode 100644 index d4dbd14..0000000 --- a/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemo.jaxx +++ /dev/null @@ -1,81 +0,0 @@ -<!-- - #%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% - --> -<org.nuiton.jaxx.demo.DemoPanel layout='{new BorderLayout()}'> - - <import> - org.nuiton.jaxx.runtime.swing.editor.SimpleTimeEditor - - static org.nuiton.i18n.I18n.t - </import> - - <!-- model --> - <SimpleTimeEditorDemoModel id='demoModel'/> - - <Table insets='0' fill='both' weightx='1' constraints='BorderLayout.NORTH'> - <row> - <cell> - <JPanel id="configPanel"> - - <!--JCheckBox id='useFloat' - text='jaxxdemo.numbereditor.useFloat' - selected='true'/> - - <JCheckBox id='useSign' - text='jaxxdemo.numbereditor.useSign' - selected='true'/> - - <JCheckBox id='showPopupButton' - text='jaxxdemo.numbereditor.showPopupButton' - selected='true'/> - - <JCheckBox id='showResetButton' - text='jaxxdemo.numbereditor.showReset' - selected='true'/> - - <JCheckBox id='autoPopup' - text='jaxxdemo.numbereditor.autoPopup' - selected='false'/--> - - </JPanel> - </cell> - </row> - <row> - <cell> - <SimpleTimeEditor id='editor' constructorParams='this' - border='{new TitledBorder(t("jaxxdemo.timeeditor.editor"))}'/> - </cell> - </row> - <row> - <cell> - - <JPanel id='resultPane'> - - <JLabel constraints='BorderLayout.CENTER' - text='{t("jaxxdemo.timeeditor.value", demoModel.getTime())}'/> - </JPanel> - - </cell> - </row> - </Table> - - -</org.nuiton.jaxx.demo.DemoPanel> diff --git a/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemo.jcss b/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemo.jcss deleted file mode 100644 index b58e6a4..0000000 --- a/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemo.jcss +++ /dev/null @@ -1,37 +0,0 @@ -/* - * #%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% - */ -#configPanel { - border:{new TitledBorder(t("jaxxdemo.numbereditor.configuration"))}; - layout:{new GridLayout(0,1)}; -} - -#editor { - property:"time"; - border:{new TitledBorder(t("jaxxdemo.timeeditor.editor"))}; - bean:{demoModel}; - date:{demoModel.getTime()}; -} - -#resultPane { - border:{new TitledBorder(t("jaxxdemo.timeeditor.model"))}; - layout:{new BorderLayout()}; -} diff --git a/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoHandler.java b/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoHandler.java deleted file mode 100644 index 6839ce3..0000000 --- a/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoHandler.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.nuiton.jaxx.demo.component.jaxx.editor; - -/* - * #%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% - */ - -import org.nuiton.jaxx.runtime.spi.UIHandler; - -/** - * Created on 11/22/13. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.6 - */ -public class SimpleTimeEditorDemoHandler implements UIHandler<SimpleTimeEditorDemo> { - @Override - public void beforeInit(SimpleTimeEditorDemo ui) { - - } - - @Override - public void afterInit(SimpleTimeEditorDemo ui) { - // init time editor - ui.editor.init(); - - // set current time in model - ui.demoModel.setTime(new java.util.Date()); - } -} diff --git a/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoModel.java b/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoModel.java deleted file mode 100644 index 9ed6381..0000000 --- a/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoModel.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * #%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% - */ -package org.nuiton.jaxx.demo.component.jaxx.editor; - -import org.nuiton.jaxx.runtime.swing.editor.SimpleTimeEditor; -import org.jdesktop.beans.AbstractSerializableBean; - -import java.util.Date; - -/** - * Model of a bean using the {@link SimpleTimeEditor}. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.6 - */ -public class SimpleTimeEditorDemoModel extends AbstractSerializableBean { - - public static final String TIME_PROPERTY = "time"; - - private static final long serialVersionUID = 1L; - - protected Date time; - - public Date getTime() { - return time; - } - - public void setTime(Date time) { - Date old = this.time; - this.time = time; - firePropertyChange(TIME_PROPERTY, old, time); - } - - -} diff --git a/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/TimeEditorDemo.jaxx b/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/TimeEditorDemo.jaxx deleted file mode 100644 index 268ff2a..0000000 --- a/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/TimeEditorDemo.jaxx +++ /dev/null @@ -1,84 +0,0 @@ -<!-- - #%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% - --> -<org.nuiton.jaxx.demo.DemoPanel layout='{new BorderLayout()}'> - - <import> - org.nuiton.jaxx.runtime.swing.editor.TimeEditor - static org.nuiton.i18n.I18n.t - </import> - - <!-- model --> - <org.nuiton.jaxx.demo.component.jaxx.editor.TimeEditorDemoModel id='demoModel'/> - - <script><![CDATA[ - -void $afterCompleteSetup() { - - // init time editor - editor.init(); - - // set current time in model - demoModel.setTime(new java.util.Date()); -} -]]> - </script> - - - <Table insets='0' fill='both' weightx='1' constraints='BorderLayout.NORTH'> - <row> - <cell> - <JPanel id="configPanel"> - - <JPanel layout='{new BorderLayout()}'> - - <JLabel id='labelConfigLabel' constraints='BorderLayout.WEST'/> - - <JTextField id='labelConfig' constraints='BorderLayout.CENTER'/> - </JPanel> - - </JPanel> - </cell> - </row> - <row> - <cell> - <org.nuiton.jaxx.runtime.swing.editor.TimeEditor id='editor' constructorParams='this' property='time' - border='{new TitledBorder(t("jaxxdemo.timeeditor.editor"))}' - bean='{demoModel}' - date="{demoModel.getTime()}" - label="{labelConfig.getText()}"/> - </cell> - </row> - <row> - <cell> - - <JPanel id='resultPane'> - - <JLabel constraints='BorderLayout.CENTER' - text='{t("jaxxdemo.timeeditor.value", demoModel.getTime())}'/> - </JPanel> - - </cell> - </row> - </Table> - - -</org.nuiton.jaxx.demo.DemoPanel> diff --git a/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/TimeEditorDemo.jcss b/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/TimeEditorDemo.jcss deleted file mode 100644 index 5483202..0000000 --- a/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/TimeEditorDemo.jcss +++ /dev/null @@ -1,47 +0,0 @@ -/* - * #%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% - */ -#configPanel { - border:{new TitledBorder(t("jaxxdemo.numbereditor.configuration"))}; - layout:{new GridLayout(0,1)}; -} - -#labelConfigLabel { - text:"jaxxdemo.timeeditor.label"; -} - -#labelConfig { - text:{t("jaxxdemo.timeeditor.editor")}; -} - -/*FIXME tchemit 2010-09-02 make this works -#editor { - property:"time"; - border:{new TitledBorder(t("jaxxdemo.timeeditor.editor"))}; - bean:{demoModel}; - date:{demoModel.getTime()}; - label:{labelConfig.getText()}; -}*/ - -#resultPane { - border:{new TitledBorder(t("jaxxdemo.timeeditor.model"))}; - layout:{new BorderLayout()}; -} diff --git a/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/TimeEditorDemoModel.java b/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/TimeEditorDemoModel.java deleted file mode 100644 index 95a5549..0000000 --- a/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/TimeEditorDemoModel.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * #%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% - */ -package org.nuiton.jaxx.demo.component.jaxx.editor; - -import org.nuiton.jaxx.runtime.swing.editor.TimeEditor; -import org.jdesktop.beans.AbstractSerializableBean; - -import java.util.Date; - -/** - * Model of a bean using the {@link TimeEditor}. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.2 - */ -public class TimeEditorDemoModel extends AbstractSerializableBean { - - public static final String TIME_PROPERTY = "time"; - - private static final long serialVersionUID = 1L; - - protected Date time; - - public Date getTime() { - return time; - } - - public void setTime(Date time) { - Date old = this.time; - this.time = time; - firePropertyChange(TIME_PROPERTY, old, time); - } - -} diff --git a/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/gis/CoordinateDemo.jaxx b/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/gis/CoordinateDemo.jaxx deleted file mode 100644 index 99ba05d..0000000 --- a/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/gis/CoordinateDemo.jaxx +++ /dev/null @@ -1,97 +0,0 @@ -<!-- - #%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% - --> -<org.nuiton.jaxx.demo.DemoPanel layout='{new BorderLayout()}'> - - <import> - org.nuiton.jaxx.runtime.swing.editor.NumberEditor - org.nuiton.jaxx.runtime.swing.editor.gis.DmsCoordinate - org.nuiton.jaxx.runtime.swing.editor.gis.DmsCoordinateEditor - org.nuiton.jaxx.runtime.swing.editor.gis.DmdCoordinate - org.nuiton.jaxx.runtime.swing.editor.gis.DmdCoordinateEditor - </import> - - <!-- model --> - <CoordinateDemoModel id='model'/> - - <!-- internal editor models --> - <DmsCoordinate id='latitudeDms'/> - <DmdCoordinate id='latitudeDmd'/> - <Float id='latitudeDd' javaBean='null'/> - <DmsCoordinate id='longitudeDms'/> - <DmdCoordinate id='longitudeDmd'/> - <Float id='longitudeDd' javaBean='null'/> - - <Table insets='0' fill='both' weightx='1' constraints='BorderLayout.NORTH'> - <row> - <cell> - <JPanel id='config' layout='{new GridLayout(1,0)}'> - - <JPanel id='configLatitude' layout='{new GridLayout(0,1)}'> - <JCheckBox id='latitudeShowReset'/> - <JRadioButton id='latitudeUseDms' - onActionPerformed='handler.useLatitudeDmsEditor()'/> - <JRadioButton id='latitudeUseDmd' - onActionPerformed='handler.useLatitudeDmdEditor()'/> - <JRadioButton id='latitudeUseDd' - onActionPerformed='handler.useLatitudeDdEditor()'/> - </JPanel> - <JPanel id='configLongitude' layout='{new GridLayout(0,1)}'> - <JCheckBox id='longitudeShowReset'/> - <JRadioButton id='longitudeUseDms' - onActionPerformed='handler.useLongitudeDmsEditor()'/> - <JRadioButton id='longitudeUseDmd' - onActionPerformed='handler.useLongitudeDmdEditor()'/> - <JRadioButton id='longitudeUseDd' - onActionPerformed='handler.useLongitudeDdEditor()'/> - </JPanel> - </JPanel> - </cell> - </row> - <row> - <cell> - <JPanel layout='{new GridLayout(1,0)}'> - <JPanel id='latitudePane' layout='{new GridLayout(0,1)}'> - <DmsCoordinateEditor id='latitudeDmsEditor' constructorParams='this'/> - <DmdCoordinateEditor id='latitudeDmdEditor' constructorParams='this'/> - <NumberEditor id='latitudeDdEditor' constructorParams='this'/> - </JPanel> - <JPanel id='longitudePane' layout='{new GridLayout(0,1)}'> - <DmsCoordinateEditor id='longitudeDmsEditor' - constructorParams='this'/> - <DmdCoordinateEditor id='longitudeDmdEditor' - constructorParams='this'/> - <NumberEditor id='longitudeDdEditor' constructorParams='this'/> - </JPanel> - </JPanel> - </cell> - </row> - <row> - <cell> - <JPanel id='result' layout='{new GridLayout(0,1)}'> - <JLabel id='resultLatitude'/> - <JLabel id='resultLongitude'/> - - </JPanel> - </cell> - </row> - </Table> -</org.nuiton.jaxx.demo.DemoPanel> diff --git a/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/gis/CoordinateDemo.jcss b/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/gis/CoordinateDemo.jcss deleted file mode 100644 index b7f5505..0000000 --- a/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/gis/CoordinateDemo.jcss +++ /dev/null @@ -1,146 +0,0 @@ -/* - * #%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% - */ - -#config { - border: {new TitledBorder(t("jaxxdemo.numbereditor.configuration"))}; -} - -#latitudeShowReset { - text: "jaxxdemo.coordinate.showReset"; - selected: true; -} - -#latitudeUseDms { - text: "jaxxdemo.coordinate.latitudeDms"; - value: DMS; - buttonGroup: latitudeEditor; - selected: true; -} - -#latitudeUseDmd { - text: "jaxxdemo.coordinate.latitudeDmd"; - value: DMD; - buttonGroup: latitudeEditor; -} - -#latitudeUseDd { - text: "jaxxdemo.coordinate.latitudeDd"; - value: "DD"; - buttonGroup: latitudeEditor; - selected: true; -} - -#longitudeShowReset { - text: "jaxxdemo.numbereditor.showReset"; - selected: true; -} - -#longitudeUseDms { - text: "jaxxdemo.coordinate.longitudeDms"; - value: DMS; - buttonGroup: longitudeEditor; - selected: true; -} - -#longitudeUseDmd { - text: "jaxxdemo.coordinate.longitudeDmd"; - value: DMD; - buttonGroup: longitudeEditor; -} - -#longitudeUseDd { - text: "jaxxdemo.coordinate.longitudeDd"; - value: "DD"; - buttonGroup: longitudeEditor; -} - -#latitudePane { - border: {new TitledBorder(t("jaxxdemo.coordinate.latitude"))}; -} - -#latitudeDmsEditor { - bean: {latitudeDms}; - propertySign: sign; - propertyDegree: degree; - propertyMinute: minute; - propertySecond: second; - showReset: {latitudeShowReset.isSelected()}; -} - -#latitudeDmdEditor { - bean: {latitudeDmd}; - propertySign: sign; - propertyDegree: degree; - propertyMinute: minute; - propertyDecimal: decimal; - showReset: {latitudeShowReset.isSelected()}; -} - -#latitudeDdEditor { - bean: {this}; - property: latitudeDd; - showReset: {latitudeShowReset.isSelected()}; - useFloat: true; - useSign: true; -} - -#longitudePane { - border: {new TitledBorder(t("jaxxdemo.coordinate.longitude"))}; -} - -#longitudeDmsEditor { - bean: {longitudeDms}; - propertySign: sign; - propertyDegree: degree; - propertyMinute: minute; - propertySecond: second; - showReset: {longitudeShowReset.isSelected()}; -} - -#longitudeDmdEditor { - bean: {longitudeDmd}; - propertySign: sign; - propertyDegree: degree; - propertyMinute: minute; - propertyDecimal: decimal; - showReset: {longitudeShowReset.isSelected()}; -} - -#longitudeDdEditor { - bean: {this}; - property: longitudeDd; - showReset: {longitudeShowReset.isSelected()}; - useFloat: true; - useSign: true; -} - -#result { - border: {new TitledBorder(t("jaxxdemo.coordinate.result"))}; -} - -#resultLatitude { - text: {handler.getLatitudeText(model.getLatitude())}; -} - -#resultLongitude { - text: {handler.getLongitudeText(model.getLongitude())}; -} diff --git a/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/gis/CoordinateDemoHandler.java b/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/gis/CoordinateDemoHandler.java deleted file mode 100644 index bc0d149..0000000 --- a/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/gis/CoordinateDemoHandler.java +++ /dev/null @@ -1,154 +0,0 @@ -package org.nuiton.jaxx.demo.component.jaxx.editor.gis; - -/* - * #%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% - */ - -import org.nuiton.jaxx.runtime.spi.UIHandler; -import org.nuiton.jaxx.runtime.swing.editor.gis.DmdCoordinate; -import org.nuiton.jaxx.runtime.swing.editor.gis.DmsCoordinate; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import static org.nuiton.i18n.I18n.t; - -/** - * Created on 11/26/13. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.6 - */ -public class CoordinateDemoHandler implements UIHandler<CoordinateDemo> { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(CoordinateDemoHandler.class); - - private CoordinateDemo ui; - - @Override - public void beforeInit(CoordinateDemo ui) { - if (log.isInfoEnabled()) { - log.info("BeforeInit " + ui.getName()); - } - this.ui = ui; - } - - @Override - public void afterInit(CoordinateDemo ui) { - - if (log.isInfoEnabled()) { - log.info("AfterInit " + ui.getName()); - } - - ui.getLatitudeDmsEditor().init(false); - ui.getLatitudeDmdEditor().init(false); - ui.getLatitudeDdEditor().init(); - ui.getLongitudeDmsEditor().init(true); - ui.getLongitudeDmdEditor().init(true); - ui.getLongitudeDdEditor().init(); - - ui.getLatitudeDms().addPropertyChangeListener(evt -> { - DmsCoordinate source = (DmsCoordinate) evt.getSource(); - getModel().setLatitude(source.toDecimal()); - }); - ui.getLatitudeDmd().addPropertyChangeListener(evt -> { - DmdCoordinate source = (DmdCoordinate) evt.getSource(); - getModel().setLatitude(source.toDecimal()); - }); - - ui.addPropertyChangeListener("latitudeDd", evt -> { - Float source = (Float) evt.getNewValue(); - getModel().setLatitude(source); - }); - - ui.getLongitudeDms().addPropertyChangeListener(evt -> { - DmsCoordinate source = (DmsCoordinate) evt.getSource(); - getModel().setLongitude(source.toDecimal()); - }); - ui.getLongitudeDmd().addPropertyChangeListener(evt -> { - DmdCoordinate source = (DmdCoordinate) evt.getSource(); - getModel().setLongitude(source.toDecimal()); - }); - - ui.addPropertyChangeListener("longitudeDd", evt -> { - Float source = (Float) evt.getNewValue(); - getModel().setLongitude(source); - }); - - useLatitudeDmsEditor(); - useLongitudeDmsEditor(); - } - - public void useLatitudeDmsEditor() { - ui.getLatitudeDmsEditor().setValue(DmsCoordinate.valueOf(getModel().getLatitude())); - ui.getLatitudeDmsEditor().setEnabled(true); - ui.getLatitudeDmdEditor().setEnabled(false); - ui.getLatitudeDdEditor().setEnabled(false); - } - - public void useLatitudeDmdEditor() { - ui.getLatitudeDmdEditor().setValue(DmdCoordinate.valueOf(getModel().getLatitude())); - ui.getLatitudeDmsEditor().setEnabled(false); - ui.getLatitudeDmdEditor().setEnabled(true); - ui.getLatitudeDdEditor().setEnabled(false); - } - - public void useLatitudeDdEditor() { - ui.getLatitudeDdEditor().setModel(getModel().getLatitude()); - ui.getLatitudeDmsEditor().setEnabled(false); - ui.getLatitudeDmdEditor().setEnabled(false); - ui.getLatitudeDdEditor().setEnabled(true); - } - - public void useLongitudeDmsEditor() { - ui.getLongitudeDmsEditor().setValue(DmsCoordinate.valueOf(getModel().getLongitude())); - ui.getLongitudeDmsEditor().setEnabled(true); - ui.getLongitudeDmdEditor().setEnabled(false); - ui.getLongitudeDdEditor().setEnabled(false); - } - - public void useLongitudeDmdEditor() { - ui.getLongitudeDmdEditor().setValue(DmdCoordinate.valueOf(getModel().getLongitude())); - ui.getLongitudeDmsEditor().setEnabled(false); - ui.getLongitudeDmdEditor().setEnabled(true); - ui.getLongitudeDdEditor().setEnabled(false); - } - - public void useLongitudeDdEditor() { - ui.getLongitudeDdEditor().setModel(getModel().getLongitude()); - ui.getLongitudeDmsEditor().setEnabled(false); - ui.getLongitudeDmdEditor().setEnabled(false); - ui.getLongitudeDdEditor().setEnabled(true); - } - - public String getLatitudeText(Float latitude) { - return t("jaxxdemo.coordinate.result.latitude", latitude); - } - - public String getLongitudeText(Float longitude) { - return t("jaxxdemo.coordinate.result.longitude", longitude); - } - - protected CoordinateDemoModel getModel() { - return ui.getModel(); - } -} diff --git a/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/gis/CoordinateDemoModel.java b/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/gis/CoordinateDemoModel.java deleted file mode 100644 index 4a240df..0000000 --- a/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/component/jaxx/editor/gis/CoordinateDemoModel.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.nuiton.jaxx.demo.component.jaxx.editor.gis; - -/* - * #%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% - */ - -import org.jdesktop.beans.AbstractSerializableBean; - -/** - * Created on 11/26/13. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.6 - */ -public class CoordinateDemoModel extends AbstractSerializableBean { - - public static final String PROPERTY_LONGITUDE = "longitude"; - - public static final String PROPERTY_LATITUDE = "latitude"; - - private static final long serialVersionUID = 1L; - - protected Float latitude; - - protected Float longitude; - - public Float getLongitude() { - return longitude; - } - - public void setLongitude(Float longitude) { - Object oldValue = getLongitude(); - this.longitude = longitude; - firePropertyChange(PROPERTY_LONGITUDE, oldValue, longitude); - } - - public Float getLatitude() { - return latitude; - } - - public void setLatitude(Float latitude) { - Object oldValue = getLatitude(); - this.latitude = latitude; - firePropertyChange(PROPERTY_LATITUDE, oldValue, latitude); - } -} diff --git a/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/tree/DemoDataProvider.java b/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/tree/DemoDataProvider.java index 4d83a5d..890460e 100644 --- a/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/tree/DemoDataProvider.java +++ b/jaxx-demo/src/main/java/org/nuiton/jaxx/demo/tree/DemoDataProvider.java @@ -22,7 +22,6 @@ package org.nuiton.jaxx.demo.tree; -import org.nuiton.jaxx.runtime.swing.nav.NavDataProvider; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.jaxx.demo.component.jaxx.BoxedDecoratorDemo; @@ -35,8 +34,6 @@ import org.nuiton.jaxx.demo.component.jaxx.editor.DatePickerDemo; import org.nuiton.jaxx.demo.component.jaxx.editor.FileEditorDemo; import org.nuiton.jaxx.demo.component.jaxx.editor.I18nEditorDemo; import org.nuiton.jaxx.demo.component.jaxx.editor.ListSelectorDemo; -import org.nuiton.jaxx.demo.component.jaxx.editor.SimpleTimeEditorDemo; -import org.nuiton.jaxx.demo.component.jaxx.editor.gis.CoordinateDemo; import org.nuiton.jaxx.demo.component.jaxx.widgets.datetime.DateTimeEditorDemo; import org.nuiton.jaxx.demo.component.jaxx.widgets.datetime.TimeEditorDemo; import org.nuiton.jaxx.demo.component.jaxx.widgets.gis.CoordinatesEditorDemo; @@ -69,6 +66,7 @@ import org.nuiton.jaxx.demo.feature.validation.simple.SimpleBeanValidationByTabl import org.nuiton.jaxx.demo.fun.CalculatorDemo; import org.nuiton.jaxx.demo.fun.CounterDemo; import org.nuiton.jaxx.demo.fun.LabelStyleDemo; +import org.nuiton.jaxx.runtime.swing.nav.NavDataProvider; import java.util.Arrays; import java.util.HashMap; @@ -183,9 +181,6 @@ public class DemoDataProvider implements NavDataProvider { ); addMapping(n("jaxxdemo.component.jaxx.editor"), - org.nuiton.jaxx.demo.component.jaxx.editor.TimeEditorDemo.class, - SimpleTimeEditorDemo.class, - org.nuiton.jaxx.demo.component.jaxx.editor.NumberEditorDemo.class, ComboEditorDemo.class, I18nEditorDemo.class, DatePickerDemo.class, @@ -193,8 +188,7 @@ public class DemoDataProvider implements NavDataProvider { ListSelectorDemo.class, BeanComboBoxDemo.class, BeanFilterableComboBoxDemo.class, - BeanDoubleListDemo.class, - CoordinateDemo.class + BeanDoubleListDemo.class ); addMapping(n("jaxxdemo.feature"), diff --git a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/KeyStrokeEditor.java b/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/KeyStrokeEditor.java index 874c1b5..b314481 100644 --- a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/KeyStrokeEditor.java +++ b/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/KeyStrokeEditor.java @@ -21,12 +21,10 @@ */ package org.nuiton.jaxx.runtime.swing.editor; -import java.awt.event.KeyEvent; import javax.swing.JTextField; import javax.swing.KeyStroke; import javax.swing.SwingUtilities; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import java.awt.event.KeyEvent; /** * Custom text field to disable default key events @@ -35,8 +33,6 @@ import org.apache.commons.logging.LogFactory; */ public class KeyStrokeEditor extends JTextField { - private static final Log log = LogFactory.getLog(KeyStrokeEditor.class); - protected KeyStroke keyStroke; public KeyStrokeEditor() { @@ -49,10 +45,10 @@ public class KeyStrokeEditor extends JTextField { if (e.getID() == KeyEvent.KEY_PRESSED) { int keyCode = e.getKeyCode(); if (keyCode == KeyEvent.VK_SHIFT || - keyCode == KeyEvent.VK_ALT || - keyCode == KeyEvent.VK_CONTROL || - keyCode == KeyEvent.VK_ALT_GRAPH || - keyCode == KeyEvent.VK_META) { + keyCode == KeyEvent.VK_ALT || + keyCode == KeyEvent.VK_CONTROL || + keyCode == KeyEvent.VK_ALT_GRAPH || + keyCode == KeyEvent.VK_META) { return; } diff --git a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/NumberEditor.jaxx b/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/NumberEditor.jaxx deleted file mode 100644 index 2036113..0000000 --- a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/NumberEditor.jaxx +++ /dev/null @@ -1,205 +0,0 @@ -<!-- - #%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 layout='{new BorderLayout()}' - onFocusGained='textField.requestFocus()' - onFocusLost='setPopupVisible(false);popup.setVisible(false);' - onMouseExited='setPopupVisible(false);popup.setVisible(false);'> - - <import> - java.awt.Color - java.awt.BorderLayout - java.awt.GridLayout - java.awt.Dimension - - javax.swing.BorderFactory - - </import> - <!-- onFocusGained='if (autoPopup) setPopupVisible(true); textField.requestFocus();'--> - - <!-- bean property associated with the editing value --> - <String id='property' javaBean='""'/> - - <!-- bean property --> - <Object id='bean' javaBean='null'/> - - <!-- editor model --> - <Number id="model" javaBean='null'/> - - <!-- editor model type (specify it when you want to use a special type other than Integer or Float)--> - <Class id="modelType" genericType='?' javaBean='null'/> - - <!-- useFloat property --> - <Boolean id='useFloat' javaBean='false'/> - - <!-- useSign property --> - <Boolean id='useSign' javaBean='false'/> - - <!-- autoPopup property --> - <Boolean id='autoPopup' javaBean='false'/> - - <!-- showPopupButton property --> - <Boolean id='showPopupButton' javaBean='false'/> - - <!-- show reset property --> - <Boolean id='showReset' javaBean='false'/> - - <!-- show reset property --> - <String id="numberPattern" javaBean='null'/> - - <!-- internal editor model as text --> - <String id="modelText" javaBean='""'/> - - <!-- internal state --> - <Boolean id='popupVisible' javaBean='false'/> - - <!-- When a error occurs, previous valid value is repush in textField, with this flag setted to true then also reselect this content. --> - <Boolean id='selectAllTextOnError' javaBean='false'/> - - <!-- ui handler --> - <NumberEditorHandler id='handler' constructorParams='this'/> - - <!-- popup digital number editor --> - <JPopupMenu id='popup' - onPopupMenuWillBecomeVisible='showPopUpButton.setSelected(true)' - onPopupMenuWillBecomeInvisible='showPopUpButton.setSelected(false)' - onPopupMenuCanceled='showPopUpButton.setSelected(false)'> - <style source='NumberEditorPopup.jcss'/> - <JPanel layout='{new GridLayout(4,4)}' - border='{BorderFactory.createEmptyBorder(4, 4, 4, 4)}' - background='{Color.WHITE}'> - <JButton text='numbereditor.7' onActionPerformed='addChar(event)' - styleClass='digit'/> - <JButton text='numbereditor.8' onActionPerformed='addChar(event)' - styleClass='digit'/> - <JButton text='numbereditor.9' onActionPerformed='addChar(event)' - styleClass='digit'/> - <JButton text='numbereditor.clearAll' onActionPerformed='setModel(null)' - styleClass='clear' enabled='{!getModelText().isEmpty()}'/> - - - <JButton text='numbereditor.4' onActionPerformed='addChar(event)' - styleClass='digit'/> - <JButton text='numbereditor.5' onActionPerformed='addChar(event)' - styleClass='digit'/> - <JButton text='numbereditor.6' onActionPerformed='addChar(event)' - styleClass='digit'/> - <JButton text='numbereditor.clearOne' - onActionPerformed='getHandler().removeChar()' styleClass='clear' - enabled='{!(getModelText().isEmpty() || textField.getCaretPosition() ==0 )}'/> - - <JButton text='numbereditor.1' onActionPerformed='addChar(event)' - styleClass='digit'/> - <JButton text='numbereditor.2' onActionPerformed='addChar(event)' - styleClass='digit'/> - <JButton text='numbereditor.3' onActionPerformed='addChar(event)' - styleClass='digit'/> - - <JButton enabled="false"/> - - <JButton text='numbereditor.0' onActionPerformed='addChar(event)' - styleClass='digit' - enabled='{!getEditor().getModelText().equals("0")}'/> - - <JButton id='toggleSign' text='numbereditor.toggleSign' - styleClass='operator' - onActionPerformed='getHandler().toggleSign()' - enabled='{isUseSign() && !getEditor().getModelText().isEmpty()}'/> - - <JButton id='dot' text='numbereditor..' styleClass='operator' - onActionPerformed='addChar(event)' - enabled='{isUseFloat() && getEditor().getModelText().indexOf(".") == -1 }'/> - - <JButton actionIcon='numbereditor-validate' - onActionPerformed="getHandler().validate()"/> - </JPanel> - </JPopupMenu> - <script><![CDATA[ -public void init() { - handler.init(); -} - -public NumberEditor getEditor() { - return this; -} - -public void addChar(ActionEvent event) { - getHandler().addChar(((JButton)event.getSource()).getText()); -} - -void showPopup() { - if ( popupVisible || autoPopup ) { - if (!popupVisible) { - setPopupVisible(true); - } else if (!getPopup().isVisible()) { - getHandler().setPopupVisible(true); - } - } -} - -@Override -public void setToolTipText(String toolTipText) { - super.setToolTipText(toolTipText); - textField.setToolTipText(toolTipText); -} - -]]> - </script> - - <JToolBar id='toolbar' - floatable='false' - borderPainted='false' - visible='{isShowReset()}' - constraints='BorderLayout.WEST'> - <JButton id='resetButton' - actionIcon='numbereditor-reset' - toolTipText='numbereditor.action.reset.tip' - focusable='false' - focusPainted='false' - enabled='{isEnabled()}' - onActionPerformed='setModel(null)'/> - </JToolBar> - - <JTextField id='textField' - constraints='BorderLayout.CENTER' - text='{getModelText()}' - enabled='{isEnabled()}' - onKeyReleased='getHandler().setModel(textField.getText())' - onFocusGained='showPopup()'/> - - <JToolBar constraints='BorderLayout.EAST' - floatable='false' - opaque='false' - borderPainted='false' - visible='{isShowPopupButton()}' - maximumSize='{new Dimension(24,24)}'> - <JToggleButton id='showPopUpButton' - focusable='false' - focusPainted='false' - actionIcon='numbereditor-calculator' - toolTipText='numbereditor.action.show.tip' - enabled='{isEnabled()}' - onActionPerformed='getHandler().setPopupVisible(!popup.isVisible())'/> - </JToolBar> - -</JPanel> diff --git a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/NumberEditorHandler.java b/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/NumberEditorHandler.java deleted file mode 100644 index c6c4bc2..0000000 --- a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/NumberEditorHandler.java +++ /dev/null @@ -1,591 +0,0 @@ -/* - * #%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% - */ - -package org.nuiton.jaxx.runtime.swing.editor; - -import org.apache.commons.beanutils.PropertyUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.math.NumberUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.util.beans.BeanUtil; - -import javax.swing.JComponent; -import javax.swing.JTextField; -import javax.swing.SwingUtilities; -import javax.swing.text.BadLocationException; -import java.awt.Dimension; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.beans.PropertyDescriptor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import static org.nuiton.jaxx.runtime.swing.editor.NumberEditor.PROPERTY_MODEL; -import static org.nuiton.jaxx.runtime.swing.editor.NumberEditor.PROPERTY_POPUP_VISIBLE; - -/** - * Le handler de l'éditeur graphique de nombres. - * - * Note: Ce handler n'est pas staless, et chaque ui possède le sien. - * - * @author Tony Chemit - dev@tchemit.fr - * @see NumberEditor - */ -public class NumberEditorHandler { - /** Logger */ - public static final Log log = LogFactory.getLog(NumberEditorHandler.class); - - public static final String VALIDATE_PROPERTY = "validate"; - - /** editor ui */ - protected final NumberEditor editor; - - /** the mutator method on the property of boxed bean in the editor */ - protected Method mutator; - - /** the getter method on the property */ - protected Method getter; - - /** a flag to known if mutator accept null value */ - protected Boolean acceptNull; - - protected Class<?> modelType; - - protected Pattern numberPattern; - - public NumberEditorHandler(NumberEditor ui) { - editor = ui; - } - - /** initialise l'ui et les listeners d'évènements. */ - public void init() { - try { -// if (editor.getBean() == null) { -// throw new NullPointerException("can not have a null bean in ui " + editor); -// } - - editor.addPropertyChangeListener(NumberEditor.PROPERTY_NUMBER_PATTERN, evt -> { - String newPattern = (String) evt.getNewValue(); - if (log.isInfoEnabled()) { - log.info("set new numberPattern" + newPattern); - } - if (StringUtils.isEmpty(newPattern)) { - numberPattern = null; - } else { - numberPattern = Pattern.compile(newPattern); - } - }); - - editor.addPropertyChangeListener(NumberEditor.PROPERTY_SHOW_POPUP_BUTTON, evt -> { - if (log.isDebugEnabled()) { - log.debug("set showPopupButton" + evt.getNewValue() + " for " + editor.getProperty()); - } - if (editor.getPopup().isVisible()) { - setPopupVisible(false); - } - }); - - editor.addPropertyChangeListener(NumberEditor.PROPERTY_AUTO_POPUP, evt -> { - if (log.isDebugEnabled()) { - log.debug("set auto popup " + evt.getNewValue() + " for " + editor.getProperty()); - } - if (editor.getPopup().isVisible()) { - setPopupVisible(false); - } - }); - - editor.addPropertyChangeListener(PROPERTY_MODEL, evt -> { - if (log.isDebugEnabled()) { - log.debug("set new model " + evt.getNewValue() + " for " + editor.getProperty()); - } - setModel((Number) evt.getOldValue(), (Number) evt.getNewValue()); - }); - editor.addPropertyChangeListener(PROPERTY_POPUP_VISIBLE, evt -> setPopupVisible((Boolean) evt.getNewValue())); - editor.getTextField().addMouseListener(new PopupListener()); - - // Initialise le number pattern - if (StringUtils.isNotEmpty(editor.getNumberPattern())) { - numberPattern = Pattern.compile(editor.getNumberPattern()); - } - - // Determine si c'est un float - Class<?> type = editor.getModelType(); - if (editor.getModelType() == null) { - if (editor.getBean() != null) { - type = getGetter().getReturnType(); - } - } - modelType = type; - if (log.isDebugEnabled()) { - log.debug("model type to use = " + modelType); - } - //FIXME le test n'est pas assez fort (on peut avoir un long, short,...) - editor.setUseFloat(!type.equals(Integer.class) && !type.equals(int.class)); - - // Initialise le model - if (editor.getModel() == null) { - if (editor.getBean() != null) { - Number num = (Number) getGetter().invoke(editor.getBean()); - editor.setModel(num); - } - } - - /*if (editor.getResetButton().getIcon() == null) { - editor.getResetButton().setIcon(SwingUtil.createActionIcon("numbereditor-reset")); - } - if (editor.getButton().getIcon() == null) { - editor.getButton().setIcon(SwingUtil.createActionIcon("numbereditor-calculator")); - }*/ - } catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException ex) { - log.error(ex); - } - } - - /** - * Affiche ou cache la popup. - * - * @param newValue la nouvelle valeur de visibilité de la popup. - */ - public void setPopupVisible(Boolean newValue) { - - if (log.isTraceEnabled()) { - log.trace(newValue); - } - - if (newValue == null || !newValue) { - editor.getPopup().setVisible(false); - return; - } - SwingUtilities.invokeLater(() -> { - JComponent invoker = - editor.isShowPopupButton() ? - editor.getShowPopUpButton() : - editor; - Dimension dim = editor.getPopup().getPreferredSize(); - int x = (int) (invoker.getPreferredSize().getWidth() - dim.getWidth()); - editor.getPopup().show(invoker, - x, invoker.getHeight()); - editor.getTextField().requestFocus(); - }); - } - - protected String lastValidText; - - /** - * Modifie le modèle de la donnée à éditer à partir d'un evenement clavier - * - * TODO utiliser une filtre sur les donnes en entrees pour ne pas a avoir - * faire les tests ici. - * - * @param s la nouvelle valeur du modèle - */ - public void setModel(String s) { - - String text = editor.getModelText(); - if (text.equals(s)) { - // le modeèle n'a pas changé, rien a faire sur le modèle - if (log.isDebugEnabled()) { - log.debug("modelText is the same, skip !"); - } - return; - } - - if (StringUtils.isNotEmpty(s) && numberPattern != null) { - - // use given number pattern - Matcher matcher = numberPattern.matcher(s); - if (!matcher.matches()) { - - // the current text is not accepted... - if (log.isInfoEnabled()) { - log.info("Does not accept the new number " + s + - ", will reapply lastValidText : " + lastValidText); - } - - String oldText; - if (lastValidText != null) { - - // push back last valid text - oldText = lastValidText; - } else { - oldText = ""; - } - editor.getTextField().setText(oldText); - return; - } - } - - boolean canApply = false; - - boolean endWithDot = false; - - boolean isLess = false; - - Number newValue = null; - - // allow using ',' char - s = s.replaceAll(",", "."); - - if (s.trim().isEmpty()) { - // le champ est vide donc c'est la valeur null a reaffecter - s = null; - canApply = true; - } else if (s.endsWith(".")) { - s += "0"; - endWithDot = true; - } else if (editor.isUseSign() && s.length() == 1 && s.startsWith("-")) { - s = "0"; - isLess = true; - } - - //FIXME tchemit-2014-03-25 Need to bring that bug to commons-lang team - if (s != null && (s.startsWith("0.") && NumberUtils.isNumber(s.substring(1)) || NumberUtils.isNumber(s))) { - - // on a un nombre valide - - try { - Double f = Double.parseDouble(s); - if (!editor.isUseSign() && s.startsWith("-")) { - if (log.isDebugEnabled()) { - log.debug("will skip since can not allow sign on this editor but was " + f); - } - } else { - - if (!editor.isUseFloat() && s.contains(".")) { - if (log.isDebugEnabled()) { - log.debug("will skip since can not allow float on this editor but was " + f); - } - } else { - // ok on peut utilise ce modele - newValue = getRealValue(f); -// if (editor.isUseFloat()) { -// if (getMutator().getParameterTypes()[0] == BigDecimal.class) { -// newValue = BigDecimal.valueOf(f); -// } else { -// newValue = f; -// } -// } else { -// newValue = f.intValue(); -// } - canApply = true; - } - } - - } catch (NumberFormatException e) { - // rien a faire - log.debug(e); - } - } - JTextField field = editor.getTextField(); - - int oldPosition = field.getCaretPosition(); - - if (canApply) { - - if (log.isDebugEnabled()) { - log.debug("can apply new model value : " + newValue); - } - if (isLess) { - editor.setModelText("-"); - return; - } - // on peut mettre a jour le model - editor.setModel(newValue); - if (endWithDot) { - editor.setModelText(s.substring(0, s.length() - 1)); - field.setCaretPosition(oldPosition); - } - - lastValidText = editor.getModelText(); - return; - } - - // on ne peut pas appliquer, on repositionne l'ancien texte - // dans l'éditeur - - if (log.isDebugEnabled()) { - log.debug("invalid text " + s + " reput old text " + text); - } - - field.setText(text); - - lastValidText = text; - if (editor.isSelectAllTextOnError()) { - field.selectAll(); - } else { - if (oldPosition > 0) { - oldPosition--; - } - try { - field.setCaretPosition(oldPosition); - } catch (IllegalArgumentException ex) { - log.debug("CaretPosition is invalid for position : " + oldPosition, ex); - } - } - } - - private Number getRealValue(Double f) { - if (modelType == Integer.class) { - return f.intValue(); - } - if (modelType == Double.class) { - return f; - } - if (modelType == Long.class) { - return f.longValue(); - } - if (modelType == BigInteger.class) { - return new BigInteger(f.longValue() + ""); - } - if (modelType == BigDecimal.class) { - return new BigDecimal(f + ""); - } - if (modelType == Float.class || editor.isUseFloat()) { - return f.floatValue(); - } - return f.intValue(); - } - - /** - * Ajoute le caractère donné à l'endroit où est le curseur dans la zone de - * saisie et met à jour le modèle. - * - * @param s le caractère à ajouter. - */ - public void addChar(String s) { - char c = s.charAt(0); - try { - editor.getTextField().getDocument().insertString(editor.getTextField().getCaretPosition(), c + "", null); - setModel(editor.getTextField().getText()); - //setModel(editor.getModelText() + c); - - } catch (BadLocationException e) { - log.warn(e); - } - } - - /** - * Supprime le caractère juste avant le curseur du modèle (textuel) et - * met à jour la zone de saisie. - */ - public void removeChar() { - String s = editor.getModelText(); - int position = editor.getTextField().getCaretPosition(); - if (position < 1 || s.isEmpty()) { - if (log.isDebugEnabled()) { - log.debug("cannot remove when caret on first position or text empty"); - } - // on est au debut du doc, donc rien a faire - return; - } - try { - editor.getTextField().getDocument().remove(position - 1, 1); - } catch (BadLocationException ex) { - // ne devrait jamais arrive vu qu'on a fait le controle... - log.debug(ex); - return; - } - String newText = editor.getTextField().getText(); - if (log.isDebugEnabled()) { - log.debug("text updated : " + newText); - } - position--; - editor.getTextField().setCaretPosition(position); - setModel(newText); - } - - /** - * Permute le signe dans la zone de saisie et - * dans le modèle. - */ - public void toggleSign() { - String newValue = editor.getModelText(); - - if (newValue.startsWith("-")) { - setModel(newValue.substring(1)); - } else { - setModel("-" + newValue); - } - } - - /** @return l'éditeur au quel est rattaché le handler. */ - public NumberEditor getEditor() { - return editor; - } - - protected void setModel(Number oldValue, Number newValue) { - - if (log.isDebugEnabled()) { - log.debug(editor.getProperty() + " on " + editor.getBean().getClass() + " :: " + oldValue + " to " + newValue); - } - - String strValue; - if (newValue == null) { - strValue = ""; - } else { - strValue = newValue + ""; - if (editor.isUseFloat()) { - Float n = Float.parseFloat(strValue); - if ((float) n.intValue() == n) { - strValue = n.intValue() + ""; - } - } - } - - lastValidText = strValue; - editor.setModelText(strValue); - - if (editor.getBean() == null) { - return; - } - - try { - Method mutator = getMutator(); - if (newValue == null && !getAcceptNull()) { - // valeur nulle sur une propriete primitive - // on ne peut pas utiliser la valeur null, mais 0 à la place - newValue = getRealValue(0.0d); -// if (editor.isUseFloat()) { -// if (log.isInfoEnabled()) { -// log.info("use float, check mutator default type = " + mutator.getParameterTypes()[0]); -// } -// if (mutator.getParameterTypes()[0] == BigDecimal.class) { -// newValue = BigDecimal.valueOf(0); -// } else { -// newValue = 0.0f; -//// mutator.invoke(editor.getBean(), 0.0f); -// } -// } else { -// newValue = 0; -//// mutator.invoke(editor.getBean(), 0); -// } - - } //else { -// mutator.invoke(editor.getBean(), newValue); -// } - mutator.invoke(editor.getBean(), newValue); - - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - protected void validate() { - - setPopupVisible(false); - // fire validate property (to be able to notify listeners) - editor.firePropertyChange(VALIDATE_PROPERTY, null, true); - } - - protected class PopupListener extends MouseAdapter { - - @Override - public void mousePressed(MouseEvent e) { - maybeShowPopup(e); - } - - @Override - public void mouseReleased(MouseEvent e) { - maybeShowPopup(e); - } - - protected void maybeShowPopup(MouseEvent e) { - if (!e.isPopupTrigger()) { - return; - } - if (editor.isAutoPopup()) { - if (editor.isPopupVisible()) { - if (!editor.getPopup().isVisible()) { - setPopupVisible(true); - } - // popup already visible - - } else { - // set popup auto - editor.setPopupVisible(true); - - } - } else { - if (editor.isPopupVisible()) { - setPopupVisible(true); - } - } - } - } - - protected Method getMutator() { - if (mutator == null) { - mutator = BeanUtil.getMutator(editor.getBean(), editor.getProperty()); - } - return mutator; - } - - protected Method getGetter() { - if (getter == null) { - Object bean = editor.getBean(); - if (bean == null) { - throw new NullPointerException("could not find bean in " + editor); - } - String property = editor.getProperty(); - if (property == null) { - throw new NullPointerException("could not find property in " + editor); - } - if (log.isDebugEnabled()) { - log.debug("searching accessor for property " + property + " on bean of type " + bean.getClass()); - } - if (log.isTraceEnabled()) { - PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(bean); - for (PropertyDescriptor p : descriptors) { - log.trace("property discover " + p.getName() + " reader = " + p.getWriteMethod()); - } - } - try { - PropertyDescriptor descriptor = PropertyUtils.getPropertyDescriptor(bean, property); - getter = descriptor.getReadMethod(); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - return getter; - } - - public Boolean getAcceptNull() { - if (acceptNull == null) { - Method m = getMutator(); - if (m == null) { - // should never happens - throw new IllegalStateException("could not find the mutator"); - } - Class<?> returnType = m.getParameterTypes()[0]; - acceptNull = !returnType.isPrimitive(); - if (log.isDebugEnabled()) { - log.debug(acceptNull + " for mutator " + m.getName() + " type : " + returnType); - } - } - return acceptNull; - } -} diff --git a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/NumberEditorPopup.jcss b/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/NumberEditorPopup.jcss deleted file mode 100644 index c1e25c7..0000000 --- a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/NumberEditorPopup.jcss +++ /dev/null @@ -1,47 +0,0 @@ -/* - * #%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% - */ - -JButton { - font-size: 14; - focusPainted: false; - focusable: false; -} - -JButton.digit { - foreground: blue; -} - -JButton.operator { - foreground: #009900; -} - -JButton.clear { - foreground: red; -} - -JButton:mouseover { - font-weight: bold; -} - -JButton.operator:mouseover { - font-weight: normal; -} diff --git a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/SimpleTimeEditor.jaxx b/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/SimpleTimeEditor.jaxx deleted file mode 100644 index 5ff996a..0000000 --- a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/SimpleTimeEditor.jaxx +++ /dev/null @@ -1,61 +0,0 @@ -<!-- - #%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% - --> - -<Table constraints='BorderLayout.NORTH' fill='horizontal' insets='0'> - <import> - java.io.Serializable - java.util.Date - java.awt.BorderLayout - javax.swing.SpinnerNumberModel - javax.swing.DefaultBoundedRangeModel - </import> - - <!-- ui handler --> - <SimpleTimeEditorModel id='model'/> - - <!-- spinner minute editor --> - <SpinnerDateModel id="minuteModel"/> - - <SimpleTimeEditorHandler id='handler' constructorParams='this'/> - - <script><![CDATA[ -public void init() { handler.init(); } -public void setBean(Serializable bean) { model.setBean(bean); } -public void setProperty(String property ) { model.setProperty(property); } -public void setDate(Date date) { model.setDate(date); } -]]> - </script> - - <row> - <cell weightx='0.5'> - <JSpinner id='hour' - onStateChanged='handler.updateTimeModelFromHour((Integer)hour.getValue())'/> - </cell> - <cell> - <JLabel id='labelH'/> - </cell> - <cell weightx='0.5'> - <JSpinner id='minute' - onStateChanged='handler.updateTimeModelFromMinute(minuteModel.getDate())'/> - </cell> - </row> -</Table> diff --git a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/SimpleTimeEditor.jcss b/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/SimpleTimeEditor.jcss deleted file mode 100644 index a27234a..0000000 --- a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/SimpleTimeEditor.jcss +++ /dev/null @@ -1,42 +0,0 @@ -/* - * #%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% - */ - -#hour { - value: {model.getTimeModel() / 60}; - enabled: {isEnabled()}; - model: {new SpinnerNumberModel(0, 0, 23, 1)}; -} - -#labelH { - text: "timeeditor.H"; - horizontalAlignment: center; -} - -#minuteModel { - calendarField: {java.util.Calendar.MINUTE}; - value: {handler.setMinuteModel(model.getDate())}; -} - -#minute { - enabled: {isEnabled()}; - model: {minuteModel}; -} diff --git a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/SimpleTimeEditorHandler.java b/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/SimpleTimeEditorHandler.java deleted file mode 100644 index 649c379..0000000 --- a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/SimpleTimeEditorHandler.java +++ /dev/null @@ -1,283 +0,0 @@ -package org.nuiton.jaxx.runtime.swing.editor; - -/* - * #%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.nuiton.util.beans.BeanUtil; - -import javax.swing.JFormattedTextField; -import javax.swing.JSpinner; -import javax.swing.SpinnerDateModel; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.beans.PropertyChangeListener; -import java.lang.reflect.Method; -import java.util.Calendar; -import java.util.Date; - -/** - * @author Tony Chemit - dev@tchemit.fr - * @since 2.6 - */ -public class SimpleTimeEditorHandler { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(SimpleTimeEditorHandler.class); - - private static final KeyAdapter MOVE_TO_MINUTES_KEY_LISTENER = new KeyAdapter() { - - @Override - public void keyReleased(KeyEvent e) { - JFormattedTextField source = (JFormattedTextField) e.getSource(); - String text = source.getText(); - - // if the user typed 2 digits or if he typed an hour which cannot be the tens digit, - // then transfer the focus to the minute editor (cf #3833) - if (text.length() >= 2 || !text.equals("0") && !text.equals("1") && !text.equals("2")) { - source.transferFocus(); - } - } - - }; - - private final PropertyChangeListener propertyDateChanged; - - private final PropertyChangeListener propertyTimeChanged; - - private final SimpleTimeEditor editor; - - private final SimpleTimeEditorModel model; - - /** the mutator method on the property of boxed bean in the editor */ - protected Method mutator; - - protected final Calendar calendarMinute; - - protected final Calendar calendarHour; - - protected final Calendar calendarDate; - - public SimpleTimeEditorHandler(SimpleTimeEditor editor) { - this.editor = editor; - this.model = editor.getModel(); - this.calendarMinute = Calendar.getInstance(); - this.calendarHour = Calendar.getInstance(); - this.calendarDate = Calendar.getInstance(); - this.propertyDateChanged = evt -> { - Date date = (Date) evt.getNewValue(); - - if (date != null) { - calendarDate.setTime(date); - int hours = calendarDate.get(Calendar.HOUR_OF_DAY); - int minutes = calendarDate.get(Calendar.MINUTE); - if (log.isDebugEnabled()) { - log.debug("date changed : new value " + hours + ":" + minutes); - } - model.setTimeModel(hours * 60 + minutes); - - } else { - model.setTimeModel(null); - } - - }; - this.propertyTimeChanged = evt -> { - Integer time = (Integer) evt.getNewValue(); - - int hours = time / 60; - int minutes = time % 60; - - calendarDate.set(Calendar.HOUR_OF_DAY, hours); - calendarDate.set(Calendar.MINUTE, minutes); - - // push it back into the bean - - Date newValue = calendarDate.getTime(); - - if (log.isDebugEnabled()) { - log.debug(model.getProperty() + " on " + model.getBean().getClass() + " :: " + newValue); - } - - try { - getMutator().invoke(model.getBean(), newValue); - - } catch (Exception e) { - throw new RuntimeException(e); - } - }; - } - - public void init() { - - if (model.getBean() == null) { - throw new NullPointerException("can not have a null bean in ui " + editor); - } - - editor.getMinute().setEditor(new JSpinner.DateEditor(editor.getMinute(), "mm")); -// editor.getHour().setEditor(new JSpinner.DateEditor(editor.getHour(), "HH")); - - // listen to the typed text and automatically focus the minute when the user typed the hour - JSpinner.DefaultEditor hourEditor = (JSpinner.DefaultEditor) editor.getHour().getEditor(); - hourEditor.getTextField().addKeyListener(MOVE_TO_MINUTES_KEY_LISTENER); - -// TuttiUIUtil.autoSelectOnFocus(minuteEditor.getTextField()); -// JSpinner.NumberEditor hourEditor = (JSpinner.NumberEditor) editor.getHour().getEditor(); -// TuttiUIUtil.autoSelectOnFocus(hourEditor.getTextField()); - - // listen when date changes (should come from outside) - - model.addPropertyChangeListener(SimpleTimeEditorModel.PROPERTY_DATE, propertyDateChanged); - - // When time model change, let's push it back in bean - model.addPropertyChangeListener(SimpleTimeEditorModel.PROPERTY_TIME_MODEL, propertyTimeChanged); - } - - public SimpleTimeEditor getEditor() { - return editor; - } - - protected Date setMinuteModel(Date incomingDate) { - if (incomingDate == null) { - incomingDate = new Date(); - calendarMinute.setTime(incomingDate); - calendarMinute.set(Calendar.HOUR_OF_DAY, 0); - calendarMinute.set(Calendar.MINUTE, 0); - } else { - calendarMinute.setTime(incomingDate); - calendarMinute.set(Calendar.HOUR_OF_DAY, 0); - } - incomingDate = calendarMinute.getTime(); - return incomingDate; - } - - public void updateTimeModelFromHour(Integer hour) { - model.setTimeModel(hour * 60 + model.getMinute()); - } - - public void updateTimeModelFromMinute(Date minuteDate) { - - calendarMinute.setTime(minuteDate); - int newHour = calendarMinute.get(Calendar.HOUR_OF_DAY); - int newMinute = calendarMinute.get(Calendar.MINUTE); - - int oldHour = model.getHour(); - int oldMinute = model.getMinute(); - - if (oldHour == newHour && oldMinute == newMinute) { - - // do nothing, same data - if (log.isDebugEnabled()) { - log.debug("Do not update time model , stay on same time = " + oldHour + ":" + oldMinute); - } - return; - } - - // by default stay on same hour - int hour = oldHour; - - // by default, use the new minute data - - if (log.isDebugEnabled()) { - log.debug("hh:mm (old from dateModel) = " + oldHour + ":" + oldMinute); - log.debug("hh:mm (new from minuteModel) = " + newHour + ":" + newMinute); - } - - SpinnerDateModel minuteModel = editor.getMinuteModel(); - - if (newMinute == 0) { - - // minute pass to zero (check if a new hour is required) - if (newHour == 1) { - - if (oldHour == 23) { - - // can't pass from 23:59 to 0:00, stay on 23:59 - if (log.isDebugEnabled()) { - log.debug("Do not update time model , stay on hh:mm = " + oldHour + ":" + oldMinute); - } - minuteModel.setValue(minuteModel.getPreviousValue()); - return; - } - hour = (oldHour + 1) % 24; - } - } else if (newMinute == 59) { - - // minute pass to 59 (check if a new hour is required) - - if (newHour == 23) { - - if (oldHour == 0) { - - // can't pass from 0:00 to 23:59, stay on 0:00 - if (log.isDebugEnabled()) { - log.debug("Do not update time model , stay on hh:mm = " + oldHour + ":" + oldMinute); - } - minuteModel.setValue(minuteModel.getNextValue()); - return; - } - - // decrease hour - hour = (oldHour - 1) % 24; - } - } - - // date has changed - if (log.isDebugEnabled()) { - log.debug("Update time model to hh:mm = " + hour + ":" + newMinute); - } - model.setTimeModel(hour * 60 + newMinute); - } - - protected void setDate(Date oldValue, Date newValue) { - if (model.getBean() != null) { - - if (log.isDebugEnabled()) { - log.debug(model.getProperty() + " on " + model.getBean().getClass() + " :: " + oldValue + " to " + newValue); - } - - try { - getMutator().invoke(model.getBean(), newValue); - - } catch (Exception e) { - throw new RuntimeException(e); - } - } - } - - protected Method getMutator() { - if (mutator == null) { - Object bean = model.getBean(); - if (bean == null) { - throw new NullPointerException("could not find bean in " + editor); - } - String property = model.getProperty(); - if (property == null) { - throw new NullPointerException("could not find property in " + editor); - } - - mutator = BeanUtil.getMutator(bean, property); - } - return mutator; - } -} diff --git a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/SimpleTimeEditorModel.java b/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/SimpleTimeEditorModel.java deleted file mode 100644 index 6aff51d..0000000 --- a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/SimpleTimeEditorModel.java +++ /dev/null @@ -1,109 +0,0 @@ -package org.nuiton.jaxx.runtime.swing.editor; - -/* - * #%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.io.Serializable; -import java.util.Date; - -/** - * @author Tony Chemit - dev@tchemit.fr - * @since 2.6 - */ -public class SimpleTimeEditorModel extends AbstractSerializableBean { - - private static final long serialVersionUID = 1L; - - public static final String PROPERTY_DATE = "date"; - - public static final String PROPERTY_TIME_MODEL = "timeModel"; - - public static final String PROPERTY_PROPERTY = "property"; - - public static final String PROPERTY_BEAN = "bean"; - - /** Bean where to push data. */ - protected Serializable bean; - - /** Property of the bean to use. */ - protected String property; - - /** Time model in minutes. */ - protected Integer timeModel = 0; - - /** Real date which contains the edited time. */ - protected Date date; - - public Serializable getBean() { - return bean; - } - - public void setBean(Serializable bean) { - Object oldValue = getBean(); - this.bean = bean; - firePropertyChange(PROPERTY_BEAN, oldValue, bean); - } - - public String getProperty() { - return property; - } - - public void setProperty(String property) { - Object oldValue = getProperty(); - this.property = property; - firePropertyChange(PROPERTY_PROPERTY, oldValue, property); - } - - public Date getDate() { - return date; - } - - public void setDate(Date date) { - Object oldValue = getDate(); - this.date = date; - firePropertyChange(PROPERTY_DATE, oldValue, date); - } - - public Integer getTimeModel() { - return timeModel; - } - - public void setTimeModel(Integer timeModel) { - if (timeModel == null) { - timeModel = 0; - } - Object oldValue = getTimeModel(); - this.timeModel = timeModel; - firePropertyChange(PROPERTY_TIME_MODEL, oldValue, timeModel); - } - - public int getMinute() { - return timeModel % 60; - } - - public int getHour() { - return timeModel / 60; - } - -} diff --git a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/TimeEditor.jaxx b/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/TimeEditor.jaxx deleted file mode 100644 index a83a9e6..0000000 --- a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/TimeEditor.jaxx +++ /dev/null @@ -1,87 +0,0 @@ -<!-- - #%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 layout='{new BorderLayout()}'> - - <import> - java.util.Date - java.awt.BorderLayout - javax.swing.SpinnerNumberModel - javax.swing.DefaultBoundedRangeModel - </import> - - <!-- bean property --> - <String id='property' javaBean='""'/> - - <!-- title --> - <String id='label' javaBean='""'/> - - <!-- bean --> - <Object id='bean' javaBean='null'/> - - <!-- time model --> - <Integer id="timeModel" javaBean='0'/> - - <!-- the real date --> - <java.util.Date id="date" javaBean='null'/> - - <!-- spinner minute editor --> - <SpinnerDateModel id="minuteModel"/> - - <!-- ui handler --> - <TimeEditorHandler id='handler' constructorParams='this'/> - - <script><![CDATA[ -public void init() { - minute.setEditor(new JSpinner.DateEditor(minute, "mm")); - handler.init(); -} -]]> - </script> - - <Table constraints='BorderLayout.NORTH' fill='horizontal' insets='0'> - <row> - <cell> - <JLabel id='title'/> - </cell> - <cell weightx='1'> - <JLabel/> - </cell> - <cell> - <JSpinner id='hour' - onStateChanged='setTimeModel((Integer)hour.getValue() * 60 + getHandler().getMinute())'/> - </cell> - <cell> - <JLabel id='labelH'/> - </cell> - <cell> - <JSpinner id='minute' - onStateChanged='getHandler().updateTimeModelFromMinuteModel(minuteModel.getDate())'/> - </cell> - </row> - </Table> - - <JSlider id='slider' constraints='BorderLayout.SOUTH' - onStateChanged='if (!slider.getValueIsAdjusting()) setTimeModel(slider.getValue());'/> - -</JPanel> diff --git a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/TimeEditor.jcss b/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/TimeEditor.jcss deleted file mode 100644 index 9656671..0000000 --- a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/TimeEditor.jcss +++ /dev/null @@ -1,58 +0,0 @@ -/* - * #%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% - */ - -#title { - text:{getLabel()}; - horizontalAlignment:center; -} - -#hour { - value:{getTimeModel() / 60}; - enabled:{isEnabled()}; - model:{new SpinnerNumberModel(0, 0, 23, 1)}; -} - -#labelH { - text:"timeeditor.H"; - horizontalAlignment:center; -} - -#minuteModel { - calendarField:{java.util.Calendar.MINUTE}; - value:{getHandler().setMinuteModel(getDate())}; -} - -#minute { - enabled:{isEnabled()}; - model:{minuteModel}; -} - -#slider { - font-size: 11; - paintTicks:true; - paintLabels:true; - majorTickSpacing:60; - minorTickSpacing:30; - value:{getTimeModel()}; - enabled:{isEnabled()}; - model:{new DefaultBoundedRangeModel(0, 1, 0, 60 * 24)}; -} diff --git a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/TimeEditorHandler.java b/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/TimeEditorHandler.java deleted file mode 100644 index 64343ea..0000000 --- a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/TimeEditorHandler.java +++ /dev/null @@ -1,319 +0,0 @@ -/* - * #%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% - */ - -package org.nuiton.jaxx.runtime.swing.editor; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.swing.JLabel; -import javax.swing.JSlider; -import javax.swing.plaf.basic.BasicSliderUI; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.MouseWheelEvent; -import java.lang.reflect.Method; -import java.util.Calendar; -import java.util.Date; -import java.util.Dictionary; -import java.util.Hashtable; -import java.util.Map; - -import org.nuiton.util.beans.BeanUtil; - -/** @author Tony Chemit - dev@tchemit.fr */ -public class TimeEditorHandler { - - public static final Log log = LogFactory.getLog(TimeEditorHandler.class); - - public static final String BEAN_PROPERTY = "bean"; - - public static final String PROPERTY_PROPERTY = "property"; - - public static final String DATE_PROPERTY = "date"; - - public static final String TIME_MODEL_PROPERTY = "timeModel"; - - /** editor ui */ - protected final TimeEditor editor; - - /** the mutator method on the property of boxed bean in the editor */ - protected Method mutator; - - protected final Calendar calendar; - - protected final Calendar calendarMinute; - - public TimeEditorHandler(TimeEditor ui) { - editor = ui; - calendar = Calendar.getInstance(); - calendarMinute = Calendar.getInstance(); - } - - public void init() { - - if (editor.getBean() == null) { - throw new NullPointerException("can not have a null bean in ui " + editor); - } - - // create slider labels - Map<Integer, JLabel> labelTable = new Hashtable<>(); - for (int i = 0; i < 25; i += 2) { - labelTable.put(i * 60, new JLabel(i + "")); - } - JSlider slider = editor.getSlider(); - slider.setLabelTable((Dictionary<?, ?>) labelTable); - - MouseAdapter m = new MouseAdapter() { - - @Override - public void mouseClicked(MouseEvent e) { - // set the value - int value = getSliderValue(e); - JSlider slider = (JSlider) e.getComponent(); - slider.setValueIsAdjusting(true); - slider.setValue(value); - slider.setValueIsAdjusting(false); - showToolTip(e); - e.consume(); - } - - @Override - public void mouseDragged(MouseEvent e) { - showToolTip(e); - } - - @Override - public void mouseEntered(MouseEvent e) { - showToolTip(e); - } - - @Override - public void mouseMoved(MouseEvent e) { - showToolTip(e); - } - - @Override - public void mouseReleased(MouseEvent e) { - showToolTip(e); - } - - @Override - public void mouseWheelMoved(MouseWheelEvent e) { - JSlider slider = (JSlider) e.getComponent(); - - // compute new value - int nb = e.getWheelRotation(); - int value = slider.getValue() - nb; - - // set the value - slider.setValueIsAdjusting(true); - slider.setValue(value); - slider.setValueIsAdjusting(false); - e.consume(); - } - - int getSliderValue(MouseEvent e) { - JSlider slider = (JSlider) e.getSource(); - int value = -1; - if (slider.getUI() instanceof BasicSliderUI) { - BasicSliderUI ui = (BasicSliderUI) slider.getUI(); - value = slider.getOrientation() == JSlider.HORIZONTAL - ? ui.valueForXPosition(e.getX()) - : ui.valueForYPosition(e.getY()); - } - return value; - } - - void showToolTip(MouseEvent e) { - - int value = getSliderValue(e); - if (value == -1) { - return; - } - int h = value / 60; - int m = value % 60; - - String text = ""; - if (h < 10) { - text = "0"; - } - text += h + " : "; - if (m < 10) { - text += "0"; - } - text += m; - - JSlider slider = (JSlider) e.getSource(); - slider.setToolTipText(text); - - } - }; - slider.addMouseListener(m); - slider.addMouseMotionListener(m); - slider.addMouseWheelListener(m); - - // listen when date changes (should come from outside) - editor.addPropertyChangeListener(DATE_PROPERTY, evt -> { - Date date = (Date) evt.getNewValue(); - - if (date == null) { - return; - } - calendar.setTime(date); - int hours = calendar.get(Calendar.HOUR_OF_DAY); - int minutes = calendar.get(Calendar.MINUTE); - if (log.isDebugEnabled()) { - log.debug("date changed : new value " + hours + ":" + minutes); - } - getEditor().setTimeModel(hours * 60 + minutes); - }); - - // listen when time model changes (should come from editor) - editor.addPropertyChangeListener(TIME_MODEL_PROPERTY, evt -> { - Integer time = (Integer) evt.getNewValue(); - int hours = time / 60; - int minutes = time % 60; - calendar.set(Calendar.HOUR_OF_DAY, hours); - calendar.set(Calendar.MINUTE, minutes); - setDate(null, calendar.getTime()); - }); - } - - public TimeEditor getEditor() { - return editor; - } - - protected Date setMinuteModel(Date incomingDate) { - if (incomingDate == null) { - incomingDate = new Date(); - } - calendarMinute.setTime(incomingDate); - calendarMinute.set(Calendar.HOUR_OF_DAY, 0); - incomingDate = calendarMinute.getTime(); - return incomingDate; - } - - public int getMinute() { - return getEditor().getTimeModel() % 60; - } - - public int getHour() { - return getEditor().getTimeModel() / 60; - } - - public void updateTimeModelFromMinuteModel(Date minuteDate) { - - calendarMinute.setTime(minuteDate); - int newHour = calendarMinute.get(Calendar.HOUR_OF_DAY); - int newMinute = calendarMinute.get(Calendar.MINUTE); - - int oldHour = getHour(); - int oldMinute = getMinute(); - - if (oldHour == newHour && oldMinute == newMinute) { - - // do nothing, same data - if (log.isDebugEnabled()) { - log.debug("Do not update time model , stay on same time = " + oldHour + ":" + oldMinute); - } - return; - } - - // by default stay on same hour - int hour = oldHour; - - // by default, use the new minute data - - if (log.isDebugEnabled()) { - log.debug("hh:mm (old from dateModel) = " + oldHour + ":" + oldMinute); - log.debug("hh:mm (new from minuteModel) = " + newHour + ":" + newMinute); - } - - if (newMinute == 0) { - - // minute pass to zero (check if a new hour is required) - if (newHour == 1) { - - if (oldHour == 23) { - - // can't pass from 23:59 to 0:00, stay on 23:59 - if (log.isDebugEnabled()) { - log.debug("Do not update time model , stay on hh:mm = " + oldHour + ":" + oldMinute); - } - getEditor().getMinuteModel().setValue(getEditor().getMinuteModel().getPreviousValue()); - return; - } - hour = (oldHour + 1) % 24; - } - } else if (newMinute == 59) { - - // minute pass to 59 (check if a new hour is required) - - if (newHour == 23) { - - if (oldHour == 0) { - - // can't pass from 0:00 to 23:59, stay on 0:00 - if (log.isDebugEnabled()) { - log.debug("Do not update time model , stay on hh:mm = " + oldHour + ":" + oldMinute); - } - getEditor().getMinuteModel().setValue(getEditor().getMinuteModel().getNextValue()); - return; - } - - // decrease hour - hour = (oldHour - 1) % 24; - } - } - - // date has changed - if (log.isDebugEnabled()) { - log.debug("Update time model to hh:mm = " + hour + ":" + newMinute); - } - getEditor().setTimeModel(hour * 60 + newMinute); - } - - protected void setDate(Date oldValue, Date newValue) { - if (editor.getBean() == null) { - return; - } - - if (log.isDebugEnabled()) { - log.debug(editor.getProperty() + " on " + editor.getBean().getClass() + " :: " + oldValue + " to " + newValue); - } - - try { - getMutator().invoke(editor.getBean(), newValue); - - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - protected Method getMutator() { - if (mutator == null) { - mutator = BeanUtil.getMutator(editor.getBean(), editor.getProperty()); - } - return mutator; - } -} diff --git a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmdCoordinate.java b/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmdCoordinate.java deleted file mode 100644 index ffe46da..0000000 --- a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmdCoordinate.java +++ /dev/null @@ -1,336 +0,0 @@ -package org.nuiton.jaxx.runtime.swing.editor.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. - * - * Created on 10/23/13. - * - * @author Tony Chemit - dev@tchemit.fr - * @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() { - return new DmdCoordinate(); - } - - /** - * Methode statique de fabrique de position a partir d'un autre {@link DmdCoordinate}. - * - * 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. - * - * 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. - * - * 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; - } - 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() { - return isDegreeValid(false); - } - - public boolean isLongitudeDegreeValid() { - return isDegreeValid(true); - } - - 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() { - return isDecimalNull() || (0 <= decimal && decimal < 100); - } - - @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/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmdCoordinateConverter.java b/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmdCoordinateConverter.java deleted file mode 100644 index 42de403..0000000 --- a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmdCoordinateConverter.java +++ /dev/null @@ -1,143 +0,0 @@ -package org.nuiton.jaxx.runtime.swing.editor.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 - dev@tchemit.fr - * @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/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmdCoordinateEditor.jaxx b/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmdCoordinateEditor.jaxx deleted file mode 100644 index f1bec14..0000000 --- a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmdCoordinateEditor.jaxx +++ /dev/null @@ -1,58 +0,0 @@ -<!-- - #%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> - java.io.Serializable - java.awt.BorderLayout - javax.swing.JFormattedTextField - </import> - - <!-- show reset property --> - <Boolean id='showReset' javaBean='false'/> - - <!-- show reset tip --> - <String id='showResetTip' javaBean=''/> - - <!-- model --> - <DmdCoordinateEditorModel id='model'/> - - <!--<!– handler –>--> - <!--<DmdCoordinateEditorHandler id='handler' constructorParams='this'/>--> - - <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/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmdCoordinateEditor.jcss b/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmdCoordinateEditor.jcss deleted file mode 100644 index ee35e04..0000000 --- a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmdCoordinateEditor.jcss +++ /dev/null @@ -1,38 +0,0 @@ -/* - * #%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:"combobox-reset"; - toolTipText: {getShowResetTip()}; - focusable:false; - focusPainted:false; - enabled:{isEnabled()}; -} - -#editor { - enabled:{isEnabled()}; -} diff --git a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorHandler.java b/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorHandler.java deleted file mode 100644 index 854b032..0000000 --- a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorHandler.java +++ /dev/null @@ -1,303 +0,0 @@ -package org.nuiton.jaxx.runtime.swing.editor.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 com.google.common.base.Preconditions; -import org.nuiton.jaxx.runtime.spi.UIHandler; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.util.beans.BeanUtil; - -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 - dev@tchemit.fr - * @since 2.6 - */ -public class DmdCoordinateEditorHandler implements UIHandler<DmdCoordinateEditor> { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(DmdCoordinateEditorHandler.class); - - private DmdCoordinateEditor 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(DmdCoordinateEditor 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(DmdCoordinateEditor ui) { - // nothing special to do here - } - - public void init(boolean longitudeEditor) { - - final DmdCoordinateEditorModel 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 = BeanUtil.getMutator(bean, model.getPropertySign()); - Preconditions.checkNotNull(signMutator, "could not find mutator for " + model.getPropertySign()); - - degreMutator = BeanUtil.getMutator(bean, model.getPropertyDegree()); - Preconditions.checkNotNull(degreMutator, "could not find mutator for " + model.getPropertyDegree()); - - minuteMutator = BeanUtil.getMutator(bean, model.getPropertyMinute()); - Preconditions.checkNotNull(minuteMutator, "could not find mutator for " + model.getPropertyMinute()); - - decimalMutator = BeanUtil.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", 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( - DmdCoordinateEditorModel.PROPERTY_SIGN, - new ModelPropertyChangeListener(model, signMutator)); - - // When model degre changed, let's push it back in bean - model.addPropertyChangeListener( - DmdCoordinateEditorModel.PROPERTY_DEGREE, - new ModelPropertyChangeListener(model, degreMutator)); - - // When model minute changed, let's push it back in bean - model.addPropertyChangeListener( - DmdCoordinateEditorModel.PROPERTY_MINUTE, - new ModelPropertyChangeListener(model, minuteMutator)); - - // When model decimal changed, let's push it back in bean - model.addPropertyChangeListener( - DmdCoordinateEditorModel.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 DmdCoordinateEditorModel model; - - private final Method mutator; - - private ModelPropertyChangeListener(DmdCoordinateEditorModel 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/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorModel.java b/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorModel.java deleted file mode 100644 index acf3396..0000000 --- a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorModel.java +++ /dev/null @@ -1,122 +0,0 @@ -package org.nuiton.jaxx.runtime.swing.editor.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 java.io.Serializable; - -/** - * Created on 10/16/13. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.6 - */ -public class DmdCoordinateEditorModel 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 propertyDegre; - - /** 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 propertyDegre; - } - - public void setPropertyDegree(String propertyDegree) { - Object oldValue = getPropertyDegree(); - this.propertyDegre = 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() { - return COORDINATE_STRING_PATTERN; - } -} diff --git a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmsCoordinate.java b/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmsCoordinate.java deleted file mode 100644 index 8331c4c..0000000 --- a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmsCoordinate.java +++ /dev/null @@ -1,364 +0,0 @@ -package org.nuiton.jaxx.runtime.swing.editor.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. - * - * Created on 10/23/13. - * - * @author Tony Chemit - dev@tchemit.fr - * @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() { - return new DmsCoordinate(); - } - - /** - * Methode statique de fabrique de position a partir d'un autre {@link DmsCoordinate}. - * - * 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. - * - * 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. - * - * 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; - } - 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() { - return isDegreeValid(false); - } - - public boolean isLongitudeDegreeValid() { - return isDegreeValid(true); - } - - 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() { - return isSecondNull() || (0 <= second && second < 60); - } - - @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/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmsCoordinateConverter.java b/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmsCoordinateConverter.java deleted file mode 100644 index bbd42e9..0000000 --- a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmsCoordinateConverter.java +++ /dev/null @@ -1,144 +0,0 @@ -package org.nuiton.jaxx.runtime.swing.editor.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 - dev@tchemit.fr - * @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/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmsCoordinateEditor.jaxx b/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmsCoordinateEditor.jaxx deleted file mode 100644 index 11d4435..0000000 --- a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmsCoordinateEditor.jaxx +++ /dev/null @@ -1,59 +0,0 @@ -<!-- - #%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> - java.io.Serializable - java.awt.BorderLayout - javax.swing.JFormattedTextField - </import> - - <!-- show reset property --> - - <Boolean id='showReset' javaBean='false'/> - - <!-- show reset tip --> - <String id='showResetTip' javaBean=''/> - - <!-- model --> - <DmsCoordinateEditorModel id='model'/> - - <!--<!– handler –>--> - <!--<DmsCoordinateEditorHandler id='handler' constructorParams='this'/>--> - - <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/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmsCoordinateEditor.jcss b/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmsCoordinateEditor.jcss deleted file mode 100644 index ee35e04..0000000 --- a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmsCoordinateEditor.jcss +++ /dev/null @@ -1,38 +0,0 @@ -/* - * #%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:"combobox-reset"; - toolTipText: {getShowResetTip()}; - focusable:false; - focusPainted:false; - enabled:{isEnabled()}; -} - -#editor { - enabled:{isEnabled()}; -} diff --git a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorHandler.java b/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorHandler.java deleted file mode 100644 index ffe7f18..0000000 --- a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorHandler.java +++ /dev/null @@ -1,314 +0,0 @@ -package org.nuiton.jaxx.runtime.swing.editor.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 com.google.common.base.Preconditions; -import org.nuiton.jaxx.runtime.spi.UIHandler; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.util.beans.BeanUtil; - -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 - dev@tchemit.fr - * @since 2.6 - */ -public class DmsCoordinateEditorHandler implements UIHandler<DmsCoordinateEditor>{ - - /** Logger. */ - private static final Log log = - LogFactory.getLog(DmsCoordinateEditorHandler.class); - - protected DmsCoordinateEditor 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; - -// public DmsCoordinateEditorHandler(DmsCoordinateEditor 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 beforeInit(DmsCoordinateEditor 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(DmsCoordinateEditor ui) { - // nothing special to do here - } - - public void init(boolean longitudeEditor) { - - final DmsCoordinateEditorModel 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 = BeanUtil.getMutator(bean, model.getPropertySign()); - Preconditions.checkNotNull(signMutator, "could not find mutator for " + model.getPropertySign()); - - degreMutator = BeanUtil.getMutator(bean, model.getPropertyDegree()); - Preconditions.checkNotNull(degreMutator, "could not find mutator for " + model.getPropertyDegree()); - - minuteMutator = BeanUtil.getMutator(bean, model.getPropertyMinute()); - Preconditions.checkNotNull(minuteMutator, "could not find mutator for " + model.getPropertyMinute()); - - secondMutator = BeanUtil.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", 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( - DmsCoordinateEditorModel.PROPERTY_SIGN, - new ModelPropertyChangeListener(model, signMutator)); - - // When model degre changed, let's push it back in bean - model.addPropertyChangeListener( - DmsCoordinateEditorModel.PROPERTY_DEGREE, - new ModelPropertyChangeListener(model, degreMutator)); - - // When model minute changed, let's push it back in bean - model.addPropertyChangeListener( - DmsCoordinateEditorModel.PROPERTY_MINUTE, - new ModelPropertyChangeListener(model, minuteMutator)); - - // When model second changed, let's push it back in bean - model.addPropertyChangeListener( - DmsCoordinateEditorModel.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 DmsCoordinateEditorModel model; - - private final Method mutator; - - private ModelPropertyChangeListener(DmsCoordinateEditorModel 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/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorModel.java b/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorModel.java deleted file mode 100644 index 0868d6f..0000000 --- a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorModel.java +++ /dev/null @@ -1,122 +0,0 @@ -package org.nuiton.jaxx.runtime.swing.editor.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 java.io.Serializable; - -/** - * Created on 10/16/13. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.6 - */ -public class DmsCoordinateEditorModel 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/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/MaskFormatterFromConverter.java b/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/MaskFormatterFromConverter.java deleted file mode 100644 index b505de9..0000000 --- a/jaxx-widgets/src/main/java/org/nuiton/jaxx/runtime/swing/editor/gis/MaskFormatterFromConverter.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.nuiton.jaxx.runtime.swing.editor.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 - dev@tchemit.fr - * @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<>(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 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/src/main/resources/META-INF/services/org.nuiton.converter.NuitonConverter b/jaxx-widgets/src/main/resources/META-INF/services/org.nuiton.converter.NuitonConverter deleted file mode 100644 index e26305d..0000000 --- a/jaxx-widgets/src/main/resources/META-INF/services/org.nuiton.converter.NuitonConverter +++ /dev/null @@ -1,2 +0,0 @@ -org.nuiton.jaxx.runtime.swing.editor.gis.DmsCoordinateConverter -org.nuiton.jaxx.runtime.swing.editor.gis.DmdCoordinateConverter \ No newline at end of file diff --git a/jaxx-widgets/src/test/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmdCoordinateConverterTest.java b/jaxx-widgets/src/test/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmdCoordinateConverterTest.java deleted file mode 100644 index d21af49..0000000 --- a/jaxx-widgets/src/test/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmdCoordinateConverterTest.java +++ /dev/null @@ -1,102 +0,0 @@ -package org.nuiton.jaxx.runtime.swing.editor.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 - dev@tchemit.fr - * @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/src/test/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorTest.java b/jaxx-widgets/src/test/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorTest.java deleted file mode 100644 index f6b0c15..0000000 --- a/jaxx-widgets/src/test/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorTest.java +++ /dev/null @@ -1,204 +0,0 @@ -package org.nuiton.jaxx.runtime.swing.editor.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.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.jdesktop.beans.AbstractSerializableBean; - -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.text.ParseException; - -/** - * To test the {@link DmsCoordinateEditor}. - * - * Created on 10/17/13. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.6 - */ -public class DmdCoordinateEditorTest { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(DmdCoordinateEditorTest.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(); - - DmdCoordinateEditor longitudeEditor = new DmdCoordinateEditor(); - 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); - - DmdCoordinateEditor latitudeEditor = new DmdCoordinateEditor(); - 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(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(() -> { - frame.setSize(800, 200); - frame.setVisible(true); - }); - } -} diff --git a/jaxx-widgets/src/test/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmdCoordinateTest.java b/jaxx-widgets/src/test/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmdCoordinateTest.java deleted file mode 100644 index bf638f8..0000000 --- a/jaxx-widgets/src/test/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmdCoordinateTest.java +++ /dev/null @@ -1,136 +0,0 @@ -package org.nuiton.jaxx.runtime.swing.editor.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 - dev@tchemit.fr - * @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/src/test/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmsCoordinateConverterTest.java b/jaxx-widgets/src/test/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmsCoordinateConverterTest.java deleted file mode 100644 index b2c4ca1..0000000 --- a/jaxx-widgets/src/test/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmsCoordinateConverterTest.java +++ /dev/null @@ -1,105 +0,0 @@ -package org.nuiton.jaxx.runtime.swing.editor.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 - dev@tchemit.fr - * @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 = 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 = 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); - - // DmsCoordinate -> DmsCoordinate - - actualCoordinate = 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/src/test/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorTest.java b/jaxx-widgets/src/test/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorTest.java deleted file mode 100644 index 4a8c10a..0000000 --- a/jaxx-widgets/src/test/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorTest.java +++ /dev/null @@ -1,206 +0,0 @@ -package org.nuiton.jaxx.runtime.swing.editor.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.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.jdesktop.beans.AbstractSerializableBean; - -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.text.ParseException; - -/** - * To test the {@link DmsCoordinateEditor}. - * - * Created on 10/17/13. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.6 - */ -public class DmsCoordinateEditorTest { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(DmsCoordinateEditorTest.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(); - - DmsCoordinateEditor longitudeEditor = new DmsCoordinateEditor(); - 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); - - DmsCoordinateEditor latitudeEditor = new DmsCoordinateEditor(); - 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(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(() -> { - frame.setSize(800, 200); - frame.setVisible(true); - }); - } -} diff --git a/jaxx-widgets/src/test/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmsCoordinateTest.java b/jaxx-widgets/src/test/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmsCoordinateTest.java deleted file mode 100644 index 4fe48d2..0000000 --- a/jaxx-widgets/src/test/java/org/nuiton/jaxx/runtime/swing/editor/gis/DmsCoordinateTest.java +++ /dev/null @@ -1,131 +0,0 @@ -package org.nuiton.jaxx.runtime.swing.editor.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 - dev@tchemit.fr - * @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.711f; - 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/src/test/resources/log4j.properties b/jaxx-widgets/src/test/resources/log4j.properties deleted file mode 100644 index b7b98bb..0000000 --- a/jaxx-widgets/src/test/resources/log4j.properties +++ /dev/null @@ -1,30 +0,0 @@ -### -# #%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.org.nuiton=WARN -log4j.logger.org.nuiton.jaxx=INFO -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.