Jaxx-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
November 2013
- 3 participants
- 22 discussions
r2755 - in trunk/jaxx-widgets/src: main/java/jaxx/runtime/swing/editor/gis main/resources main/resources/META-INF main/resources/META-INF/services main/resources/i18n test/java/jaxx/runtime/swing/editor/gis
by tchemit@users.nuiton.org 25 Nov '13
by tchemit@users.nuiton.org 25 Nov '13
25 Nov '13
Author: tchemit
Date: 2013-11-25 16:54:51 +0100 (Mon, 25 Nov 2013)
New Revision: 2755
Url: http://nuiton.org/projects/jaxx/repository/revisions/2755
Log:
refs #2929: Introduce some coordinate editors (still need some improvements)
Added:
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateConverter.java
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateConverter.java
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/MaskFormatterFromConverter.java
trunk/jaxx-widgets/src/main/resources/META-INF/
trunk/jaxx-widgets/src/main/resources/META-INF/services/
trunk/jaxx-widgets/src/main/resources/META-INF/services/org.apache.commons.beanutils.Converter
trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmdCoordinateConverterTest.java
trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmsCoordinateConverterTest.java
trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmsCoordinateTest.java
Modified:
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinate.java
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorHandler.java
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorModel.java
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinate.java
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorHandler.java
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorModel.java
trunk/jaxx-widgets/src/main/resources/i18n/jaxx-widgets_en_GB.properties
trunk/jaxx-widgets/src/main/resources/i18n/jaxx-widgets_es_ES.properties
trunk/jaxx-widgets/src/main/resources/i18n/jaxx-widgets_fr_FR.properties
trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmdCoordinateTest.java
Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinate.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinate.java 2013-11-24 21:52:35 UTC (rev 2754)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinate.java 2013-11-25 15:54:51 UTC (rev 2755)
@@ -26,6 +26,8 @@
import org.jdesktop.beans.AbstractSerializableBean;
+import java.util.regex.Pattern;
+
/**
* Geo coordinate in degree decimal, minute format.
* <p/>
@@ -38,7 +40,11 @@
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";
@@ -191,6 +197,21 @@
if (d == 0) {
d = null;
}
+
+ if (d != null || m != null || dc != null) {
+
+ // fill with 0 other null values
+ // if one value is not null, then put zero everywhere
+ if (d == null) {
+ d = 0;
+ }
+ if (m == null) {
+ m = 0;
+ }
+ if (dc == null) {
+ dc = 0;
+ }
+ }
}
degree = d;
Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateConverter.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateConverter.java (rev 0)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateConverter.java 2013-11-25 15:54:51 UTC (rev 2755)
@@ -0,0 +1,139 @@
+package jaxx.runtime.swing.editor.gis;
+
+/*
+ * #%L
+ * JAXX :: Widgets
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+import org.apache.commons.beanutils.ConversionException;
+import org.apache.commons.beanutils.Converter;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.regex.Matcher;
+
+import static org.nuiton.i18n.I18n._;
+
+/**
+ * Created on 11/25/13.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.6
+ */
+public class DmdCoordinateConverter implements Converter {
+
+ protected boolean useSign;
+
+ protected boolean forLongitude;
+
+ public boolean isUseSign() {
+ return useSign;
+ }
+
+ public void setUseSign(boolean useSign) {
+ this.useSign = useSign;
+ }
+
+ public void setForLongitude(boolean forLongitude) {
+ this.forLongitude = forLongitude;
+ }
+
+ @Override
+ public Object convert(Class aClass, Object value) {
+
+ Object result = null;
+
+ if (value != null) {
+
+ if (!isEnabled(aClass)) {
+ throw new ConversionException(
+ _("jaxx.error.no.convertor.coordinateDmd", value));
+ }
+
+ 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) ? 0 : Integer.valueOf(degresStr);
+ Integer minutes = minutesStr.isEmpty() ? 0 : Integer.valueOf(minutesStr);
+ Integer decimal = decimalesStr.isEmpty() ? 0 : Integer.valueOf(decimalesStr);
+
+ boolean signed = degresStr.contains("-");
+ result =
+ DmdCoordinate.valueOf(signed,
+ Math.abs(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 result;
+ }
+
+ protected boolean isEnabled(Class<?> aClass) {
+ return String.class.isAssignableFrom(aClass) ||
+ DmdCoordinate.class.isAssignableFrom(aClass);
+ }
+
+ public Class<?> getType() {
+ return DmdCoordinate.class;
+ }
+
+}
+
Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateConverter.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorHandler.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorHandler.java 2013-11-24 21:52:35 UTC (rev 2754)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorHandler.java 2013-11-25 15:54:51 UTC (rev 2755)
@@ -26,7 +26,6 @@
import com.google.common.base.Preconditions;
import jaxx.runtime.swing.editor.bean.BeanUIUtil;
-import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -38,8 +37,6 @@
import java.beans.PropertyChangeListener;
import java.lang.reflect.Method;
import java.text.ParseException;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
/**
* Created on 10/16/13.
@@ -53,8 +50,6 @@
private static final Log log =
LogFactory.getLog(DmdCoordinateEditorHandler.class);
- protected static final Pattern VALUE_PATTERN = Pattern.compile("(.*)°(.*)'(.*)");
-
private final DmdCoordinateEditor ui;
protected Method signMutator;
@@ -65,16 +60,17 @@
protected Method decimalMutator;
- protected DefaultFormatterFactory unsignedFactory;
-
- protected DefaultFormatterFactory signedFactory;
-
protected boolean valueIsAdjusting;
protected boolean valueModelIsAdjusting;
+ private final DmdCoordinateConverter converter;
+
public DmdCoordinateEditorHandler(DmdCoordinateEditor ui) {
this.ui = ui;
+
+ // can't use the one from ConverterUtil since we deal with some internal states
+ this.converter = new DmdCoordinateConverter();
}
public void init() {
@@ -87,6 +83,8 @@
Preconditions.checkNotNull(model.getPropertyMinute(), "could not find propertyMinute in " + ui);
Preconditions.checkNotNull(model.getPropertyDecimal(), "could not find propertyDecimal in " + ui);
+ converter.setForLongitude(model.isLongitudeEditor());
+
Object bean = model.getBean();
signMutator = BeanUIUtil.getMutator(bean, model.getPropertySign());
Preconditions.checkNotNull(signMutator, "could not find mutator for " + model.getPropertySign());
@@ -100,68 +98,48 @@
decimalMutator = BeanUIUtil.getMutator(bean, model.getPropertyDecimal());
Preconditions.checkNotNull(decimalMutator, "could not find mutator for " + model.getPropertyDecimal());
- MaskFormatter unsignedFormatter;
+ MaskFormatter maskFormatter;
try {
String pattern = model.getMaskFormatterPattern();
- unsignedFormatter = new MaskFormatter(pattern);
- unsignedFormatter.setValidCharacters(" 01234567890");
+ maskFormatter = new MaskFormatterFromConverter<DmdCoordinate>(
+ DmdCoordinate.class, pattern, converter);
+ maskFormatter.setValidCharacters(" 01234567890");
} catch (ParseException e) {
// can't happen here
throw new RuntimeException(e);
}
- unsignedFactory = new DefaultFormatterFactory(unsignedFormatter);
- MaskFormatter signedFormatter;
- try {
+ DefaultFormatterFactory formatterFactory =
+ new DefaultFormatterFactory(maskFormatter);
- String pattern = model.getMaskFormatterPattern();
- signedFormatter = new MaskFormatter("-" + pattern);
- signedFormatter.setValidCharacters(" 01234567890");
- } catch (ParseException e) {
- // can't happen here
- throw new RuntimeException(e);
- }
- signedFactory = new DefaultFormatterFactory(signedFormatter);
-
JFormattedTextField editor = ui.getEditor();
- editor.setFormatterFactory(unsignedFactory);
+ editor.setFormatterFactory(formatterFactory);
editor.setFocusLostBehavior(JFormattedTextField.COMMIT);
// When editor changes his value, propagate it to model
editor.addPropertyChangeListener("value", new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
- String newValue = (String) evt.getNewValue();
+ DmdCoordinate newValue = (DmdCoordinate) evt.getNewValue();
if (log.isDebugEnabled()) {
log.debug("Value has changed: " + newValue);
}
- DmdCoordinate value = null;
- if (newValue != null) {
+ model.setValue(newValue);
+ }
+ });
- Matcher matcher = VALUE_PATTERN.matcher(newValue);
-
- 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) ? 0 : Integer.valueOf(degresStr);
- Integer minutes = minutesStr.isEmpty() ? 0 : Integer.valueOf(minutesStr);
- Integer decimal = decimalesStr.isEmpty() ? 0 : Integer.valueOf(decimalesStr);
-
- boolean signed = degre < 0;
- value =
- DmdCoordinate.valueOf(signed,
- Math.abs(degre),
- minutes,
- decimal);
+ // When longitudeEditor property changed, propagate to the converter
+ model.addPropertyChangeListener(
+ DmdCoordinateEditorModel.PROPERTY_LONGITUDE_EDITOR,
+ new PropertyChangeListener() {
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ Boolean newValue = (Boolean) evt.getNewValue();
+ converter.setForLongitude(newValue != null && newValue);
}
}
- model.setValue(value);
- }
- });
+ );
// When model sign changed, let's push it back in bean
model.addPropertyChangeListener(
@@ -191,40 +169,10 @@
return;
}
- String signStr = "";
- String degreeStr = "";
- String minuteStr = "";
- String decimalStr = "";
-
- if (value != null) {
-
- boolean sign = value.isSign();
- signStr = sign ? "-" : "";
-
- Integer degree = value.getDegree();
- degreeStr = degree == null ? "" : degree.toString();
-
- Integer minute = value.getMinute();
- minuteStr = minute == null ? "" : minute.toString();
-
- Integer decimal = value.getDecimal();
- decimalStr = decimal == null ? "" : decimal.toString();
- }
-
- DmdCoordinateEditorModel model = ui.getModel();
-
- String stringPattern = model.getStringPattern();
- String valueStr = String.format(
- stringPattern,
- signStr,
- StringUtils.leftPad(degreeStr, model.isLongitudeEditor() ? 3 : 2, ' '),
- StringUtils.leftPad(minuteStr, 2, ' '),
- StringUtils.leftPad(decimalStr, 2, ' '));
-
valueIsAdjusting = !pushToModel;
try {
- ui.getEditor().setValue(valueStr);
+ ui.getEditor().setValue(value);
} finally {
valueIsAdjusting = false;
}
@@ -235,7 +183,7 @@
setValue(null, true);
// use back unsigned format
- ui.getEditor().setFormatterFactory(unsignedFactory);
+ converter.setUseSign(false);
}
public void onKeyReleased(KeyEvent e) {
@@ -253,71 +201,44 @@
if (keyChar == '-') {
// try to switch unsigned to signed
+ boolean useSign = converter.isUseSign();
- if (unsignedFactory == source.getFormatterFactory()) {
+ if (useSign) {
- // switch to signed
if (log.isDebugEnabled()) {
- log.debug("Switch to signed");
+ log.debug("Switch to unsigned");
}
- newFactory = signedFactory;
+ converter.setUseSign(false);
- try {
- source.commitEdit();
- } catch (ParseException e1) {
- // ignore it
- }
+ source.setText(source.getText().substring(1).trim());
- newValue = "-" + source.getValue();
-
+ // remove a sign
+ caretPosition--;
} else {
- // switch to unsigned
-
+ // switch to signed
if (log.isDebugEnabled()) {
- log.debug("Switch to unsigned");
+ log.debug("Switch to signed");
}
- newFactory = unsignedFactory;
+ converter.setUseSign(true);
- try {
- source.commitEdit();
- } catch (ParseException e1) {
- // ignore it
- }
+ source.setText("-" + source.getText());
- newValue = ((String) source.getValue()).substring(1);
+ // add a sign
+ caretPosition++;
}
- } else {
+
try {
source.commitEdit();
} catch (ParseException e1) {
// ignore it
+ if (log.isErrorEnabled()) {
+ log.error("Could not commit edit of " + source.getText(), e1);
+ }
}
if (log.isDebugEnabled()) {
log.debug("Key pressed: newValue " + source.getValue());
}
- }
-
- if (newFactory != null) {
-
- // consume event (prevent any side-effects)
e.consume();
-
- if (log.isDebugEnabled()) {
- log.debug("Key pressed: newValue " + newValue);
- }
- source.setFormatterFactory(newFactory);
- source.setValue(newValue);
-
- if (unsignedFactory == newFactory) {
-
- // remove a sign
- caretPosition--;
- } else {
-
- // add a sign
- caretPosition++;
- }
-
source.setCaretPosition(caretPosition);
}
}
Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorModel.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorModel.java 2013-11-24 21:52:35 UTC (rev 2754)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorModel.java 2013-11-25 15:54:51 UTC (rev 2755)
@@ -145,7 +145,7 @@
}
public String getStringPattern() {
- String pattern = "%s%s°%s'%s";
+ String pattern = COORDINATE_STRING_PATTERN;
return pattern;
}
}
Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinate.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinate.java 2013-11-24 21:52:35 UTC (rev 2754)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinate.java 2013-11-25 15:54:51 UTC (rev 2755)
@@ -26,6 +26,8 @@
import org.jdesktop.beans.AbstractSerializableBean;
+import java.util.regex.Pattern;
+
/**
* Geo coordinate in degree, minute, second format.
* <p/>
@@ -36,6 +38,11 @@
*/
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";
@@ -205,11 +212,26 @@
if (s == 0) {
s = null;
}
+
+ if (d != null || m != null || s != null) {
+
+ // if one value is not null, then put zero everywhere
+ if (d == null) {
+ d = 0;
+ }
+ if (m == null) {
+ m = 0;
+ }
+ if (s == null) {
+ s = 0;
+ }
+ }
}
- if (d != null && d == 0) {
- d = null;
- }
+// if (d != null && d == 0) {
+// d = null;
+// }
+
degree = d;
minute = m;
second = s;
Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateConverter.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateConverter.java (rev 0)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateConverter.java 2013-11-25 15:54:51 UTC (rev 2755)
@@ -0,0 +1,138 @@
+package jaxx.runtime.swing.editor.gis;
+
+/*
+ * #%L
+ * JAXX :: Widgets
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+import org.apache.commons.beanutils.ConversionException;
+import org.apache.commons.beanutils.Converter;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.regex.Matcher;
+
+import static org.nuiton.i18n.I18n._;
+
+/**
+ * Created on 11/25/13.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.6
+ */
+public class DmsCoordinateConverter implements Converter {
+
+ protected boolean useSign;
+
+ protected boolean forLongitude;
+
+ public boolean isUseSign() {
+ return useSign;
+ }
+
+ public void setUseSign(boolean useSign) {
+ this.useSign = useSign;
+ }
+
+ public void setForLongitude(boolean forLongitude) {
+ this.forLongitude = forLongitude;
+ }
+
+ @Override
+ public Object convert(Class aClass, Object value) {
+
+ Object result = null;
+
+ if (value != null) {
+
+ if (!isEnabled(aClass)) {
+ throw new ConversionException(
+ _("jaxx.error.no.convertor.coordinateDmd", value));
+ }
+
+ 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) ? 0 : Integer.valueOf(degresStr);
+ Integer minutes = minutesStr.isEmpty() ? 0 : Integer.valueOf(minutesStr);
+ Integer seconds = secondsStr.isEmpty() ? 0 : Integer.valueOf(secondsStr);
+
+ boolean signed = degresStr.contains("-");
+ result = DmsCoordinate.valueOf(signed,
+ Math.abs(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 result;
+
+ }
+
+ protected boolean isEnabled(Class<?> aClass) {
+ return String.class.isAssignableFrom(aClass) ||
+ DmsCoordinate.class.isAssignableFrom(aClass);
+ }
+
+ public Class<?> getType() {
+ return DmsCoordinate.class;
+ }
+
+}
+
Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateConverter.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorHandler.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorHandler.java 2013-11-24 21:52:35 UTC (rev 2754)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorHandler.java 2013-11-25 15:54:51 UTC (rev 2755)
@@ -26,7 +26,6 @@
import com.google.common.base.Preconditions;
import jaxx.runtime.swing.editor.bean.BeanUIUtil;
-import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -38,8 +37,6 @@
import java.beans.PropertyChangeListener;
import java.lang.reflect.Method;
import java.text.ParseException;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
/**
* Created on 10/16/13.
@@ -53,9 +50,6 @@
private static final Log log =
LogFactory.getLog(DmsCoordinateEditorHandler.class);
- protected static final Pattern VALUE_PATTERN =
- Pattern.compile("(.*)°(.*)'(.*)''");
-
private final DmsCoordinateEditor ui;
protected Method signMutator;
@@ -66,16 +60,17 @@
protected Method secondMutator;
- protected DefaultFormatterFactory unsignedFactory;
-
- protected DefaultFormatterFactory signedFactory;
-
protected boolean valueIsAdjusting;
protected boolean valueModelIsAdjusting;
+ private final DmsCoordinateConverter converter;
+
public DmsCoordinateEditorHandler(DmsCoordinateEditor ui) {
this.ui = ui;
+
+ // can't use the one from ConverterUtil since we deal with some internal states
+ this.converter = new DmsCoordinateConverter();
}
public void init() {
@@ -101,68 +96,49 @@
secondMutator = BeanUIUtil.getMutator(bean, model.getPropertySecond());
Preconditions.checkNotNull(secondMutator, "could not find mutator for " + model.getPropertySecond());
- MaskFormatter unsignedFormatter;
- try {
+ converter.setForLongitude(model.isLongitudeEditor());
- String pattern = model.getMaskFormatterPattern();
- unsignedFormatter = new MaskFormatter(pattern);
- unsignedFormatter.setValidCharacters(" 01234567890");
- } catch (ParseException e) {
- // can't happen here
- throw new RuntimeException(e);
- }
- unsignedFactory = new DefaultFormatterFactory(unsignedFormatter);
-
- MaskFormatter signedFormatter;
+ MaskFormatter maskFormatter;
try {
String pattern = model.getMaskFormatterPattern();
- signedFormatter = new MaskFormatter("-" + pattern);
- signedFormatter.setValidCharacters(" 01234567890");
+ maskFormatter = new MaskFormatterFromConverter<DmsCoordinate>(
+ DmsCoordinate.class,
+ pattern, converter);
+ maskFormatter.setValidCharacters(" 01234567890");
} catch (ParseException e) {
// can't happen here
throw new RuntimeException(e);
}
- signedFactory = new DefaultFormatterFactory(signedFormatter);
+ DefaultFormatterFactory formatterFactory = new DefaultFormatterFactory(maskFormatter);
JFormattedTextField editor = ui.getEditor();
- editor.setFormatterFactory(unsignedFactory);
+ editor.setFormatterFactory(formatterFactory);
editor.setFocusLostBehavior(JFormattedTextField.COMMIT);
// When editor changes his value, propagate it to model
editor.addPropertyChangeListener("value", new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
- String newValue = (String) evt.getNewValue();
+ DmsCoordinate newValue = (DmsCoordinate) evt.getNewValue();
if (log.isDebugEnabled()) {
log.debug("Value has changed: " + newValue);
}
- DmsCoordinate value = null;
- if (newValue != null) {
+ model.setValue(newValue);
+ }
+ });
- Matcher matcher = VALUE_PATTERN.matcher(newValue);
-
- 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) ? 0 : Integer.valueOf(degresStr);
- Integer minutes = minutesStr.isEmpty() ? 0 : Integer.valueOf(minutesStr);
- Integer seconds = secondsStr.isEmpty() ? 0 : Integer.valueOf(secondsStr);
-
- boolean signed = degre < 0;
- value =
- DmsCoordinate.valueOf(signed,
- Math.abs(degre),
- minutes,
- seconds);
+ // When longitudeEditor property changed, propagate to the converter
+ model.addPropertyChangeListener(
+ DmsCoordinateEditorModel.PROPERTY_LONGITUDE_EDITOR,
+ new PropertyChangeListener() {
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ Boolean newValue = (Boolean) evt.getNewValue();
+ converter.setForLongitude(newValue != null && newValue);
}
}
- model.setValue(value);
- }
- });
+ );
// When model sign changed, let's push it back in bean
model.addPropertyChangeListener(
@@ -192,38 +168,10 @@
return;
}
- String signStr = "";
- String degreeStr = "";
- String minuteStr = "";
- String secondStr = "";
- if (value != null) {
-
- boolean sign = value.isSign();
- signStr = sign ? "-" : "";
-
- Integer degree = value.getDegree();
- degreeStr = degree == null ? "" : degree.toString();
-
- Integer minute = value.getMinute();
- minuteStr = minute == null ? "" : minute.toString();
-
- Integer second = value.getSecond();
- secondStr = second == null ? "" : second.toString();
- }
-
- DmsCoordinateEditorModel model = ui.getModel();
- String stringPattern = model.getStringPattern();
- String valueStr = String.format(
- stringPattern,
- signStr,
- StringUtils.leftPad(degreeStr, model.isLongitudeEditor() ? 3 : 2, ' '),
- StringUtils.leftPad(minuteStr, 2, ' '),
- StringUtils.leftPad(secondStr, 2, ' '));
-
valueIsAdjusting = !pushToModel;
try {
- ui.getEditor().setValue(valueStr);
+ ui.getEditor().setValue(value);
} finally {
valueIsAdjusting = false;
}
@@ -234,7 +182,7 @@
setValue(null, true);
// use back unsigned format
- ui.getEditor().setFormatterFactory(unsignedFactory);
+ converter.setUseSign(false);
}
public void onKeyReleased(KeyEvent e) {
@@ -247,77 +195,55 @@
log.debug("Key pressed: " + keyChar + " (caret position: " + caretPosition + ")");
}
- String newValue = null;
- DefaultFormatterFactory newFactory = null;
+ boolean needConsume = false;
if (keyChar == '-') {
// try to switch unsigned to signed
- if (unsignedFactory == source.getFormatterFactory()) {
+ boolean useSign = converter.isUseSign();
- // switch to signed
+ if (useSign) {
+
if (log.isDebugEnabled()) {
- log.debug("Switch to signed");
+ log.debug("Switch to unsigned");
}
- newFactory = signedFactory;
+ converter.setUseSign(false);
- try {
- source.commitEdit();
- } catch (ParseException e1) {
- // ignore it
- }
+ source.setText(source.getText().substring(1).trim());
- newValue = "-" + source.getValue();
-
+ // remove a sign
+ caretPosition--;
} else {
- // switch to unsigned
-
+ // switch to signed
if (log.isDebugEnabled()) {
- log.debug("Switch to unsigned");
+ log.debug("Switch to signed");
}
- newFactory = unsignedFactory;
+ converter.setUseSign(true);
- try {
- source.commitEdit();
- } catch (ParseException e1) {
- // ignore it
- }
+ source.setText("-" + source.getText());
- newValue = ((String) source.getValue()).substring(1);
+ // add a sign
+ caretPosition++;
}
- } else {
- try {
- source.commitEdit();
- } catch (ParseException e1) {
- // ignore it
- }
- if (log.isDebugEnabled()) {
- log.debug("Key pressed: newValue " + source.getValue());
- }
+
+ needConsume = useSign != converter.isUseSign();
}
- if (newFactory != null) {
-
- // consume event (prevent any side-effects)
- e.consume();
-
-
- if (log.isDebugEnabled()) {
- log.debug("Key pressed: newValue " + newValue);
+ try {
+ source.commitEdit();
+ } catch (ParseException e1) {
+ // ignore it
+ if (log.isErrorEnabled()) {
+ log.error("Could not commit edit of " + source.getText(), e1);
}
- source.setFormatterFactory(newFactory);
- source.setValue(newValue);
+ }
- if (unsignedFactory == newFactory) {
+ if (log.isDebugEnabled()) {
+ log.debug("Key pressed: newValue " + source.getValue());
+ }
- // remove a sign
- caretPosition--;
- } else {
-
- // add a sign
- caretPosition++;
- }
-
+ if (needConsume) {
+ e.consume();
source.setCaretPosition(caretPosition);
}
}
Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorModel.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorModel.java 2013-11-24 21:52:35 UTC (rev 2754)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorModel.java 2013-11-25 15:54:51 UTC (rev 2755)
@@ -145,7 +145,6 @@
}
public String getStringPattern() {
- String pattern = "%s%s°%s'%s''";
- return pattern;
+ return COORDINATE_STRING_PATTERN;
}
}
Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/MaskFormatterFromConverter.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/MaskFormatterFromConverter.java (rev 0)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/MaskFormatterFromConverter.java 2013-11-25 15:54:51 UTC (rev 2755)
@@ -0,0 +1,71 @@
+package jaxx.runtime.swing.editor.gis;
+
+/*
+ * #%L
+ * JAXX :: Widgets
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+import org.apache.commons.beanutils.Converter;
+
+import javax.swing.text.MaskFormatter;
+import java.text.ParseException;
+
+/**
+ * Created on 11/25/13.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.6
+ */
+public class MaskFormatterFromConverter<O> extends MaskFormatter {
+
+ private static final long serialVersionUID = 1L;
+
+ private final Converter converter;
+
+ private final Class<O> type;
+
+ public MaskFormatterFromConverter(Class<O> type,
+ String pattern,
+ Converter converter) throws ParseException {
+ super(pattern);
+ this.type = type;
+ this.converter = converter;
+ }
+
+ @Override
+ public String valueToString(Object value) throws ParseException {
+ return (String) converter.convert(String.class, value);
+ }
+
+ @Override
+ public Object stringToValue(String value) throws ParseException {
+ return converter.convert(type, value);
+ }
+
+ protected Converter getConverter() {
+ return converter;
+ }
+
+ protected Class<O> getType() {
+ return type;
+ }
+}
Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/MaskFormatterFromConverter.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/jaxx-widgets/src/main/resources/META-INF/services/org.apache.commons.beanutils.Converter
===================================================================
--- trunk/jaxx-widgets/src/main/resources/META-INF/services/org.apache.commons.beanutils.Converter (rev 0)
+++ trunk/jaxx-widgets/src/main/resources/META-INF/services/org.apache.commons.beanutils.Converter 2013-11-25 15:54:51 UTC (rev 2755)
@@ -0,0 +1,2 @@
+jaxx.runtime.swing.editor.gis.DmsCoordinateConverter
+jaxx.runtime.swing.editor.gis.DmdCoordinateConverter
\ No newline at end of file
Property changes on: trunk/jaxx-widgets/src/main/resources/META-INF/services/org.apache.commons.beanutils.Converter
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/jaxx-widgets/src/main/resources/i18n/jaxx-widgets_en_GB.properties
===================================================================
--- trunk/jaxx-widgets/src/main/resources/i18n/jaxx-widgets_en_GB.properties 2013-11-24 21:52:35 UTC (rev 2754)
+++ trunk/jaxx-widgets/src/main/resources/i18n/jaxx-widgets_en_GB.properties 2013-11-25 15:54:51 UTC (rev 2755)
@@ -78,6 +78,8 @@
i18neditor.popup.title=Change language
i18neditor.selected=Selected language \: %1$s
i18neditor.unselected=Select this langage \: %1$s
+jaxx.error.no.convertor.coordinateDmd=Impossible de convert form (or to) a DMD coordinate (incoming value\: %s)
+jaxx.error.no.convertor.coordinateDms=Impossible de convert form (or to) a DMS coordinate (incoming value\: %s)
memorywidget.memory=%d/%dMb
numbereditor..=.
numbereditor.0=0
Modified: trunk/jaxx-widgets/src/main/resources/i18n/jaxx-widgets_es_ES.properties
===================================================================
--- trunk/jaxx-widgets/src/main/resources/i18n/jaxx-widgets_es_ES.properties 2013-11-24 21:52:35 UTC (rev 2754)
+++ trunk/jaxx-widgets/src/main/resources/i18n/jaxx-widgets_es_ES.properties 2013-11-25 15:54:51 UTC (rev 2755)
@@ -78,6 +78,8 @@
i18neditor.popup.title=Cambiar idioma
i18neditor.selected=Idioma usado actualmente \: %1$s
i18neditor.unselected=Para usar este idioma \: %1$s
+jaxx.error.no.convertor.coordinateDmd=
+jaxx.error.no.convertor.coordinateDms=
memorywidget.memory=%d/%dMo
numbereditor..=.
numbereditor.0=0
Modified: trunk/jaxx-widgets/src/main/resources/i18n/jaxx-widgets_fr_FR.properties
===================================================================
--- trunk/jaxx-widgets/src/main/resources/i18n/jaxx-widgets_fr_FR.properties 2013-11-24 21:52:35 UTC (rev 2754)
+++ trunk/jaxx-widgets/src/main/resources/i18n/jaxx-widgets_fr_FR.properties 2013-11-25 15:54:51 UTC (rev 2755)
@@ -78,6 +78,8 @@
i18neditor.popup.title=Changer de langue
i18neditor.selected=Langue actuellement utilisée \: %1$s
i18neditor.unselected=Pour utiliser cette langue \: %1$s
+jaxx.error.no.convertor.coordinateDmd=Impossible de convertir en (ou depuis) une coordonée DMD depuis la valeur %s
+jaxx.error.no.convertor.coordinateDms=Impossible de convertir en (ou depuis) une coordonée DMS depuis la valeur %s
memorywidget.memory=%d/%dMo
numbereditor..=.
numbereditor.0=0
Added: trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmdCoordinateConverterTest.java
===================================================================
--- trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmdCoordinateConverterTest.java (rev 0)
+++ trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmdCoordinateConverterTest.java 2013-11-25 15:54:51 UTC (rev 2755)
@@ -0,0 +1,93 @@
+package jaxx.runtime.swing.editor.gis;
+
+/*
+ * #%L
+ * JAXX :: Widgets
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.nuiton.util.converter.ConverterUtil;
+
+/**
+ * Created on 11/25/13.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.6
+ */
+public class DmdCoordinateConverterTest {
+
+
+ @Test
+ public void testConvert() throws Exception {
+
+ ConverterUtil.initConverters();
+
+ testConversion(false, "- 0° 0'44", DmdCoordinate.valueOf(-0.007333f));
+ testConversion(false, " 0° 0'44", DmdCoordinate.valueOf(0.007333f));
+ testConversion(false, " 0°39'99", DmdCoordinate.valueOf(false, 0, 39, 99));
+
+ testConversion(true, "- 0° 0'44", DmdCoordinate.valueOf(-0.007333f));
+ testConversion(true, " 0° 0'44", DmdCoordinate.valueOf(0.007333f));
+ testConversion(true, " 0°39'99", DmdCoordinate.valueOf(false, 0, 39, 99));
+ }
+
+ 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 = (DmdCoordinate) 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 = (String) converter.convert(String.class, expectedCoordinate);
+
+ Assert.assertNotNull(actualStr);
+ Assert.assertEquals(expectedString, actualStr);
+
+ // String -> String
+
+ actualStr = (String) converter.convert(String.class, expectedString);
+
+ Assert.assertNotNull(actualStr);
+ Assert.assertEquals(expectedString, actualStr);
+
+ // DmdCoordinate -> DmdCoordinate
+ actualCoordinate = (DmdCoordinate) 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());
+ }
+}
Property changes on: trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmdCoordinateConverterTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmdCoordinateTest.java
===================================================================
--- trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmdCoordinateTest.java 2013-11-24 21:52:35 UTC (rev 2754)
+++ trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmdCoordinateTest.java 2013-11-25 15:54:51 UTC (rev 2755)
@@ -39,34 +39,22 @@
public void testFromDecimal() throws Exception {
{
- DmdCoordinate actual = DmdCoordinate.empty();
+ DmdCoordinate coordinate = DmdCoordinate.empty();
- actual.fromDecimal(42.7f);
+ coordinate.fromDecimal(42.7f);
- Integer expectedDegree = 42;
- Integer expectedMinute = 42;
- Integer expectedDecimal = null;
-
- Assert.assertEquals(expectedDegree, actual.getDegree());
- Assert.assertEquals(expectedMinute, actual.getMinute());
- Assert.assertEquals(expectedDecimal, actual.getDecimal());
+ assertDmdCoordinate(coordinate, false, 42,42,0);
}
{
- DmdCoordinate actual = DmdCoordinate.empty();
+ DmdCoordinate coordinate = DmdCoordinate.empty();
float decimalExcepted = 42.707f;
- actual.fromDecimal(decimalExcepted);
+ coordinate.fromDecimal(decimalExcepted);
- Integer expectedDegree = 42;
- Integer expectedMinute = 42;
- Integer expectedDecimal = 42;
+ assertDmdCoordinate(coordinate, false, 42,42,42);
- Assert.assertEquals(expectedDegree, actual.getDegree());
- Assert.assertEquals(expectedMinute, actual.getMinute());
- Assert.assertEquals(expectedDecimal, actual.getDecimal());
-
- Float decimal = actual.toDecimal();
+ Float decimal = coordinate.toDecimal();
Assert.assertEquals(decimalExcepted, decimal, 0.001);
}
}
@@ -75,32 +63,26 @@
public void testToDecimal() throws Exception {
{
- DmdCoordinate component = DmdCoordinate.empty();
- component.setDegree(42);
- component.setMinute(42);
- component.setDecimal(42);
- Float actual = component.toDecimal();
+ 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 component = DmdCoordinate.empty();
- component.setDegree(12);
- component.setMinute(12);
- Float actual = component.toDecimal();
+ DmdCoordinate coordinate = DmdCoordinate.empty();
+ coordinate.setDegree(12);
+ coordinate.setMinute(12);
+ Float actual = coordinate.toDecimal();
Float expected = 12.2f;
Assert.assertEquals(expected, actual, 0.0001);
- component.fromDecimal(expected);
+ coordinate.fromDecimal(expected);
- Integer expectedDegree = 12;
- Integer expectedMinute = 12;
- Integer expectedDecimal = null;
-
- Assert.assertEquals(expectedDegree, component.getDegree());
- Assert.assertEquals(expectedMinute, component.getMinute());
- Assert.assertEquals(expectedDecimal, component.getDecimal());
+ assertDmdCoordinate(coordinate, false, 12,12,0);
}
{
@@ -114,13 +96,35 @@
component.fromDecimal(expected);
- Integer expectedDegree = 12;
- Integer expectedMinute = 12;
- Integer expectedDecimal = 20;
+ assertDmdCoordinate(component, false, 12,12,20);
- Assert.assertEquals(expectedDegree, component.getDegree());
- Assert.assertEquals(expectedMinute, component.getMinute());
- Assert.assertEquals(expectedDecimal, component.getDecimal());
}
}
+
+ @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, 0, 0, 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());
+ }
}
Added: trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmsCoordinateConverterTest.java
===================================================================
--- trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmsCoordinateConverterTest.java (rev 0)
+++ trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmsCoordinateConverterTest.java 2013-11-25 15:54:51 UTC (rev 2755)
@@ -0,0 +1,93 @@
+package jaxx.runtime.swing.editor.gis;
+
+/*
+ * #%L
+ * JAXX :: Widgets
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.nuiton.util.converter.ConverterUtil;
+
+/**
+ * Created on 11/25/13.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.6
+ */
+public class DmsCoordinateConverterTest {
+
+
+ @Test
+ public void testConvert() throws Exception {
+
+ ConverterUtil.initConverters();
+
+ testConversion(false, "- 0° 0'26''", DmsCoordinate.valueOf(-0.007333f));
+ testConversion(false, " 0° 0'26''", DmsCoordinate.valueOf(0.007333f));
+ testConversion(false, " 0°39'59''", DmsCoordinate.valueOf(false, 0, 39, 59));
+
+ testConversion(true, "- 0° 0'26''", DmsCoordinate.valueOf(-0.007333f));
+ testConversion(true, " 0° 0'26''", DmsCoordinate.valueOf(0.007333f));
+ testConversion(true, " 0°39'59''", DmsCoordinate.valueOf(false, 0, 39, 59));
+ }
+
+ protected void testConversion(boolean forLongitude, String expectedString, DmsCoordinate expectedCoordinate) {
+
+ DmsCoordinateConverter converter = (DmsCoordinateConverter) ConverterUtil.getConverter(DmsCoordinate.class);
+ converter.setForLongitude(forLongitude);
+ Assert.assertNotNull(converter);
+
+ String actualStr;
+ DmsCoordinate actualCoordinate;
+
+ // String -> DmsCoordinate
+ actualCoordinate = (DmsCoordinate) converter.convert(DmsCoordinate.class, expectedString);
+ Assert.assertNotNull(actualCoordinate);
+ Assert.assertEquals(actualCoordinate.isSign(), expectedCoordinate.isSign());
+ Assert.assertEquals(actualCoordinate.getDegree(), expectedCoordinate.getDegree());
+ Assert.assertEquals(actualCoordinate.getMinute(), expectedCoordinate.getMinute());
+ Assert.assertEquals(actualCoordinate.getSecond(), expectedCoordinate.getSecond());
+
+ // DmsCoordinate -> String
+
+ actualStr = (String) converter.convert(String.class, expectedCoordinate);
+
+ Assert.assertNotNull(actualStr);
+ Assert.assertEquals(expectedString, actualStr);
+
+ // String -> String
+
+ actualStr = (String) converter.convert(String.class, expectedString);
+
+ Assert.assertNotNull(actualStr);
+ Assert.assertEquals(expectedString, actualStr);
+
+ // DmsCoordinate -> DmsCoordinate
+ actualCoordinate = (DmsCoordinate) converter.convert(DmsCoordinate.class, expectedCoordinate);
+ Assert.assertNotNull(actualCoordinate);
+ Assert.assertEquals(actualCoordinate.isSign(), expectedCoordinate.isSign());
+ Assert.assertEquals(actualCoordinate.getDegree(), expectedCoordinate.getDegree());
+ Assert.assertEquals(actualCoordinate.getMinute(), expectedCoordinate.getMinute());
+ Assert.assertEquals(actualCoordinate.getSecond(), expectedCoordinate.getSecond());
+ }
+}
Property changes on: trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmsCoordinateConverterTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmsCoordinateTest.java
===================================================================
--- trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmsCoordinateTest.java (rev 0)
+++ trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmsCoordinateTest.java 2013-11-25 15:54:51 UTC (rev 2755)
@@ -0,0 +1,133 @@
+package jaxx.runtime.swing.editor.gis;
+
+/*
+ * #%L
+ * JAXX :: Widgets
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Created on 11/25/13.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.6
+ */
+public class DmsCoordinateTest {
+
+ @Test
+ public void testFromDecimal() throws Exception {
+
+ {
+ DmsCoordinate actual = DmsCoordinate.empty();
+
+ actual.fromDecimal(42.7f);
+
+ assertDmsCoordinate(actual, false, 42, 42, 0);
+ }
+
+ {
+ 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, 0);
+
+ }
+
+ {
+ 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, 0, 0, 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());
+ }
+}
Property changes on: trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmsCoordinateTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
1
0
r2754 - in trunk: jaxx-compiler/src/main/java/jaxx/compiler/reflect jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis jaxx-widgets/src/test/java/jaxx/runtime jaxx-widgets/src/test/java/jaxx/runtime/swing jaxx-widgets/src/test/java/jaxx/runtime/swing/editor jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis
by tchemit@users.nuiton.org 24 Nov '13
by tchemit@users.nuiton.org 24 Nov '13
24 Nov '13
Author: tchemit
Date: 2013-11-24 22:52:35 +0100 (Sun, 24 Nov 2013)
New Revision: 2754
Url: http://nuiton.org/projects/jaxx/repository/revisions/2754
Log:
refs #2929: Introduce some coordinate editors
Added:
trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/
trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/
trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/
trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorTest.java
trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmdCoordinateTest.java
trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorTest.java
Modified:
trunk/jaxx-compiler/src/main/java/jaxx/compiler/reflect/ClassDescriptorHelper.java
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinate.java
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditor.css
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditor.jaxx
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorHandler.java
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorModel.java
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinate.java
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditor.css
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditor.jaxx
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorHandler.java
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorModel.java
Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/reflect/ClassDescriptorHelper.java
===================================================================
--- trunk/jaxx-compiler/src/main/java/jaxx/compiler/reflect/ClassDescriptorHelper.java 2013-11-24 08:47:25 UTC (rev 2753)
+++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/reflect/ClassDescriptorHelper.java 2013-11-24 21:52:35 UTC (rev 2754)
@@ -517,7 +517,8 @@
public static JAXXObjectDescriptor getJAXXObjectDescriptor(Class<?> jaxxClass) {
if (!JAXXObject.class.isAssignableFrom(jaxxClass) ||
- JAXXObject.class.equals(jaxxClass)) {
+ JAXXObject.class.equals(jaxxClass) ||
+ jaxxClass.isInterface()) {
return null;
}
try {
Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinate.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinate.java 2013-11-24 08:47:25 UTC (rev 2753)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinate.java 2013-11-24 21:52:35 UTC (rev 2754)
@@ -1,5 +1,29 @@
package jaxx.runtime.swing.editor.gis;
+/*
+ * #%L
+ * JAXX :: Widgets
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
import org.jdesktop.beans.AbstractSerializableBean;
/**
Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinate.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditor.css
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditor.css 2013-11-24 08:47:25 UTC (rev 2753)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditor.css 2013-11-24 21:52:35 UTC (rev 2754)
@@ -1,3 +1,26 @@
+/*
+ * #%L
+ * JAXX :: Widgets
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
#toolbarLeft {
floatable:false;
borderPainted:false;
Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditor.css
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditor.jaxx
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditor.jaxx 2013-11-24 08:47:25 UTC (rev 2753)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditor.jaxx 2013-11-24 21:52:35 UTC (rev 2754)
@@ -1,3 +1,26 @@
+<!--
+ #%L
+ JAXX :: Widgets
+ $Id$
+ $HeadURL$
+ %%
+ Copyright (C) 2008 - 2013 CodeLutin
+ %%
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Lesser Public License for more details.
+
+ You should have received a copy of the GNU General Lesser Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ #L%
+ -->
<JPanel id='editorPanel' layout='{new BorderLayout()}'
onFocusGained='editor.requestFocus()'>
<import>
Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditor.jaxx
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorHandler.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorHandler.java 2013-11-24 08:47:25 UTC (rev 2753)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorHandler.java 2013-11-24 21:52:35 UTC (rev 2754)
@@ -1,5 +1,29 @@
package jaxx.runtime.swing.editor.gis;
+/*
+ * #%L
+ * JAXX :: Widgets
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
import com.google.common.base.Preconditions;
import jaxx.runtime.swing.editor.bean.BeanUIUtil;
import org.apache.commons.lang3.StringUtils;
Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorHandler.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorModel.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorModel.java 2013-11-24 08:47:25 UTC (rev 2753)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorModel.java 2013-11-24 21:52:35 UTC (rev 2754)
@@ -1,5 +1,29 @@
package jaxx.runtime.swing.editor.gis;
+/*
+ * #%L
+ * JAXX :: Widgets
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
import java.io.Serializable;
/**
Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorModel.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinate.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinate.java 2013-11-24 08:47:25 UTC (rev 2753)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinate.java 2013-11-24 21:52:35 UTC (rev 2754)
@@ -1,5 +1,29 @@
package jaxx.runtime.swing.editor.gis;
+/*
+ * #%L
+ * JAXX :: Widgets
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
import org.jdesktop.beans.AbstractSerializableBean;
/**
Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinate.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditor.css
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditor.css 2013-11-24 08:47:25 UTC (rev 2753)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditor.css 2013-11-24 21:52:35 UTC (rev 2754)
@@ -1,3 +1,26 @@
+/*
+ * #%L
+ * JAXX :: Widgets
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
#toolbarLeft {
floatable:false;
borderPainted:false;
Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditor.css
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditor.jaxx
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditor.jaxx 2013-11-24 08:47:25 UTC (rev 2753)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditor.jaxx 2013-11-24 21:52:35 UTC (rev 2754)
@@ -1,3 +1,26 @@
+<!--
+ #%L
+ JAXX :: Widgets
+ $Id$
+ $HeadURL$
+ %%
+ Copyright (C) 2008 - 2013 CodeLutin
+ %%
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Lesser Public License for more details.
+
+ You should have received a copy of the GNU General Lesser Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ #L%
+ -->
<JPanel id='editorPanel' layout='{new BorderLayout()}'
onFocusGained='editor.requestFocus()'>
<import>
Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditor.jaxx
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorHandler.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorHandler.java 2013-11-24 08:47:25 UTC (rev 2753)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorHandler.java 2013-11-24 21:52:35 UTC (rev 2754)
@@ -1,5 +1,29 @@
package jaxx.runtime.swing.editor.gis;
+/*
+ * #%L
+ * JAXX :: Widgets
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
import com.google.common.base.Preconditions;
import jaxx.runtime.swing.editor.bean.BeanUIUtil;
import org.apache.commons.lang3.StringUtils;
Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorHandler.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorModel.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorModel.java 2013-11-24 08:47:25 UTC (rev 2753)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorModel.java 2013-11-24 21:52:35 UTC (rev 2754)
@@ -1,5 +1,29 @@
package jaxx.runtime.swing.editor.gis;
+/*
+ * #%L
+ * JAXX :: Widgets
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
import java.io.Serializable;
/**
Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorModel.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Added: trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorTest.java
===================================================================
--- trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorTest.java (rev 0)
+++ trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorTest.java 2013-11-24 21:52:35 UTC (rev 2754)
@@ -0,0 +1,216 @@
+package jaxx.runtime.swing.editor.gis;
+
+/*
+ * #%L
+ * JAXX :: Widgets
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+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.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.text.ParseException;
+
+/**
+ * To test the {@link DmsCoordinateEditor}.
+ * <p/>
+ * Created on 10/17/13.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @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.setLongitudeEditor(true);
+ longitudeEditor.setShowReset(true);
+ longitudeEditor.init();
+
+ 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.setLongitudeEditor(false);
+ latitudeEditor.setShowReset(true);
+ latitudeEditor.init();
+
+ final JLabel latitudeResult = new JLabel();
+ final JLabel longitudeResult = new JLabel();
+
+ bean.addPropertyChangeListener(new PropertyChangeListener() {
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ EditorBean source = (EditorBean) evt.getSource();
+ String propertyName = evt.getPropertyName();
+ if (log.isInfoEnabled()) {
+ log.info("[" + propertyName + "] value changed: " + evt.getNewValue());
+ }
+ if (propertyName.startsWith("longitude")) {
+ longitudeResult.setText(source.getLongitude().toString());
+ } else {
+
+ latitudeResult.setText(source.getLatitude().toString());
+ }
+ }
+ });
+
+ JPanel longitudeEditorPanel = new JPanel(new GridLayout());
+ longitudeEditorPanel.setBorder(new TitledBorder("Longitude"));
+ longitudeEditorPanel.add(BorderLayout.CENTER, longitudeEditor);
+ longitudeEditorPanel.add(BorderLayout.EAST, longitudeResult);
+
+ JPanel latitudeEditorPanel = new JPanel(new GridLayout());
+ latitudeEditorPanel.setBorder(new TitledBorder("Latitude"));
+ latitudeEditorPanel.add(BorderLayout.CENTER, latitudeEditor);
+ latitudeEditorPanel.add(BorderLayout.EAST, latitudeResult);
+
+ JPanel panel = new JPanel(new GridLayout(0, 1));
+ panel.add(longitudeEditorPanel);
+ panel.add(latitudeEditorPanel);
+
+ final JDialog frame = new JDialog();
+
+ frame.setContentPane(panel);
+
+ SwingUtilities.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ frame.setSize(800, 200);
+ frame.setVisible(true);
+ }
+ });
+ }
+}
Property changes on: trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmdCoordinateTest.java
===================================================================
--- trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmdCoordinateTest.java (rev 0)
+++ trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmdCoordinateTest.java 2013-11-24 21:52:35 UTC (rev 2754)
@@ -0,0 +1,126 @@
+package jaxx.runtime.swing.editor.gis;
+
+/*
+ * #%L
+ * JAXX :: Widgets
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Created on 10/25/13.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.6
+ */
+public class DmdCoordinateTest {
+
+ @Test
+ public void testFromDecimal() throws Exception {
+
+ {
+ DmdCoordinate actual = DmdCoordinate.empty();
+
+ actual.fromDecimal(42.7f);
+
+ Integer expectedDegree = 42;
+ Integer expectedMinute = 42;
+ Integer expectedDecimal = null;
+
+ Assert.assertEquals(expectedDegree, actual.getDegree());
+ Assert.assertEquals(expectedMinute, actual.getMinute());
+ Assert.assertEquals(expectedDecimal, actual.getDecimal());
+ }
+
+ {
+ DmdCoordinate actual = DmdCoordinate.empty();
+
+ float decimalExcepted = 42.707f;
+ actual.fromDecimal(decimalExcepted);
+
+ Integer expectedDegree = 42;
+ Integer expectedMinute = 42;
+ Integer expectedDecimal = 42;
+
+ Assert.assertEquals(expectedDegree, actual.getDegree());
+ Assert.assertEquals(expectedMinute, actual.getMinute());
+ Assert.assertEquals(expectedDecimal, actual.getDecimal());
+
+ Float decimal = actual.toDecimal();
+ Assert.assertEquals(decimalExcepted, decimal, 0.001);
+ }
+ }
+
+ @Test
+ public void testToDecimal() throws Exception {
+
+ {
+ DmdCoordinate component = DmdCoordinate.empty();
+ component.setDegree(42);
+ component.setMinute(42);
+ component.setDecimal(42);
+ Float actual = component.toDecimal();
+ Float expected = 42.707f;
+ Assert.assertEquals(expected, actual, 0.001);
+ }
+
+ {
+ DmdCoordinate component = DmdCoordinate.empty();
+ component.setDegree(12);
+ component.setMinute(12);
+ Float actual = component.toDecimal();
+ Float expected = 12.2f;
+ Assert.assertEquals(expected, actual, 0.0001);
+
+ component.fromDecimal(expected);
+
+ Integer expectedDegree = 12;
+ Integer expectedMinute = 12;
+ Integer expectedDecimal = null;
+
+ Assert.assertEquals(expectedDegree, component.getDegree());
+ Assert.assertEquals(expectedMinute, component.getMinute());
+ Assert.assertEquals(expectedDecimal, component.getDecimal());
+ }
+
+ {
+ 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);
+
+ Integer expectedDegree = 12;
+ Integer expectedMinute = 12;
+ Integer expectedDecimal = 20;
+
+ Assert.assertEquals(expectedDegree, component.getDegree());
+ Assert.assertEquals(expectedMinute, component.getMinute());
+ Assert.assertEquals(expectedDecimal, component.getDecimal());
+ }
+ }
+}
Property changes on: trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmdCoordinateTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorTest.java
===================================================================
--- trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorTest.java (rev 0)
+++ trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorTest.java 2013-11-24 21:52:35 UTC (rev 2754)
@@ -0,0 +1,218 @@
+package jaxx.runtime.swing.editor.gis;
+
+/*
+ * #%L
+ * JAXX :: Widgets
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+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.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.text.ParseException;
+
+/**
+ * To test the {@link DmsCoordinateEditor}.
+ * <p/>
+ * Created on 10/17/13.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @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 setLongitudeDegre(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 setLatitudeDegre(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.setLongitudeEditor(true);
+ longitudeEditor.setShowReset(true);
+ longitudeEditor.init();
+
+ 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.setLongitudeEditor(false);
+ latitudeEditor.setShowReset(true);
+ latitudeEditor.init();
+
+ final JLabel latitudeResult = new JLabel();
+ final JLabel longitudeResult = new JLabel();
+
+ bean.addPropertyChangeListener(new PropertyChangeListener() {
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ EditorBean source = (EditorBean) evt.getSource();
+ String propertyName = evt.getPropertyName();
+ if (log.isInfoEnabled()) {
+ log.info("[" + propertyName + "] value changed: " + evt.getNewValue());
+ }
+ if (propertyName.startsWith("longitude")) {
+ longitudeResult.setText(source.getLongitude().toString());
+ } else {
+
+ latitudeResult.setText(source.getLatitude().toString());
+ }
+ }
+ });
+
+ JPanel longitudeEditorPanel = new JPanel(new GridLayout());
+ longitudeEditorPanel.setBorder(new TitledBorder("Longitude"));
+ longitudeEditorPanel.add(BorderLayout.CENTER, longitudeEditor);
+ longitudeEditorPanel.add(BorderLayout.EAST, longitudeResult);
+
+ JPanel latitudeEditorPanel = new JPanel(new GridLayout());
+ latitudeEditorPanel.setBorder(new TitledBorder("Latitude"));
+ latitudeEditorPanel.add(BorderLayout.CENTER, latitudeEditor);
+ latitudeEditorPanel.add(BorderLayout.EAST, latitudeResult);
+
+ JPanel panel = new JPanel(new GridLayout(0, 1));
+ panel.add(longitudeEditorPanel);
+ panel.add(latitudeEditorPanel);
+
+ final JDialog frame = new JDialog();
+
+ frame.setContentPane(panel);
+
+ SwingUtilities.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ frame.setSize(800, 200);
+ frame.setVisible(true);
+ }
+ });
+ }
+}
Property changes on: trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
1
0
r2753 - in trunk: . jaxx-compiler jaxx-config jaxx-demo jaxx-maven-plugin jaxx-runtime jaxx-validator jaxx-widgets jaxx-widgets/src/main/java/jaxx/runtime/swing/editor
by tchemit@users.nuiton.org 24 Nov '13
by tchemit@users.nuiton.org 24 Nov '13
24 Nov '13
Author: tchemit
Date: 2013-11-24 09:47:25 +0100 (Sun, 24 Nov 2013)
New Revision: 2753
Url: http://nuiton.org/projects/jaxx/repository/revisions/2753
Log:
move to version 2.6
Modified:
trunk/jaxx-compiler/pom.xml
trunk/jaxx-config/pom.xml
trunk/jaxx-demo/pom.xml
trunk/jaxx-maven-plugin/pom.xml
trunk/jaxx-runtime/pom.xml
trunk/jaxx-validator/pom.xml
trunk/jaxx-widgets/pom.xml
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditorHandler.java
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditorModel.java
trunk/pom.xml
Modified: trunk/jaxx-compiler/pom.xml
===================================================================
--- trunk/jaxx-compiler/pom.xml 2013-11-24 08:44:06 UTC (rev 2752)
+++ trunk/jaxx-compiler/pom.xml 2013-11-24 08:47:25 UTC (rev 2753)
@@ -30,7 +30,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>jaxx</artifactId>
- <version>2.5.31-SNAPSHOT</version>
+ <version>2.6-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.jaxx</groupId>
Modified: trunk/jaxx-config/pom.xml
===================================================================
--- trunk/jaxx-config/pom.xml 2013-11-24 08:44:06 UTC (rev 2752)
+++ trunk/jaxx-config/pom.xml 2013-11-24 08:47:25 UTC (rev 2753)
@@ -31,7 +31,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>jaxx</artifactId>
- <version>2.5.31-SNAPSHOT</version>
+ <version>2.6-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.jaxx</groupId>
Modified: trunk/jaxx-demo/pom.xml
===================================================================
--- trunk/jaxx-demo/pom.xml 2013-11-24 08:44:06 UTC (rev 2752)
+++ trunk/jaxx-demo/pom.xml 2013-11-24 08:47:25 UTC (rev 2753)
@@ -30,7 +30,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>jaxx</artifactId>
- <version>2.5.31-SNAPSHOT</version>
+ <version>2.6-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.jaxx</groupId>
Modified: trunk/jaxx-maven-plugin/pom.xml
===================================================================
--- trunk/jaxx-maven-plugin/pom.xml 2013-11-24 08:44:06 UTC (rev 2752)
+++ trunk/jaxx-maven-plugin/pom.xml 2013-11-24 08:47:25 UTC (rev 2753)
@@ -31,7 +31,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>jaxx</artifactId>
- <version>2.5.31-SNAPSHOT</version>
+ <version>2.6-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.jaxx</groupId>
Modified: trunk/jaxx-runtime/pom.xml
===================================================================
--- trunk/jaxx-runtime/pom.xml 2013-11-24 08:44:06 UTC (rev 2752)
+++ trunk/jaxx-runtime/pom.xml 2013-11-24 08:47:25 UTC (rev 2753)
@@ -30,7 +30,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>jaxx</artifactId>
- <version>2.5.31-SNAPSHOT</version>
+ <version>2.6-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.jaxx</groupId>
Modified: trunk/jaxx-validator/pom.xml
===================================================================
--- trunk/jaxx-validator/pom.xml 2013-11-24 08:44:06 UTC (rev 2752)
+++ trunk/jaxx-validator/pom.xml 2013-11-24 08:47:25 UTC (rev 2753)
@@ -30,7 +30,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>jaxx</artifactId>
- <version>2.5.31-SNAPSHOT</version>
+ <version>2.6-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.jaxx</groupId>
Modified: trunk/jaxx-widgets/pom.xml
===================================================================
--- trunk/jaxx-widgets/pom.xml 2013-11-24 08:44:06 UTC (rev 2752)
+++ trunk/jaxx-widgets/pom.xml 2013-11-24 08:47:25 UTC (rev 2753)
@@ -31,7 +31,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>jaxx</artifactId>
- <version>2.5.31-SNAPSHOT</version>
+ <version>2.6-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.jaxx</groupId>
Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditorHandler.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditorHandler.java 2013-11-24 08:44:06 UTC (rev 2752)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditorHandler.java 2013-11-24 08:47:25 UTC (rev 2753)
@@ -38,7 +38,7 @@
/**
* @author Tony CHEMIT <chemit(a)codelutin.com>
- * @since 2.5.31
+ * @since 2.6
*/
public class SimpleTimeEditorHandler {
Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditorModel.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditorModel.java 2013-11-24 08:44:06 UTC (rev 2752)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditorModel.java 2013-11-24 08:47:25 UTC (rev 2753)
@@ -31,7 +31,7 @@
/**
* @author Tony CHEMIT <chemit(a)codelutin.com>
- * @since 2.5.31
+ * @since 2.6
*/
public class SimpleTimeEditorModel extends AbstractSerializableBean {
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2013-11-24 08:44:06 UTC (rev 2752)
+++ trunk/pom.xml 2013-11-24 08:47:25 UTC (rev 2753)
@@ -34,7 +34,7 @@
</parent>
<artifactId>jaxx</artifactId>
- <version>2.5.31-SNAPSHOT</version>
+ <version>2.6-SNAPSHOT</version>
<modules>
<module>jaxx-runtime</module>
1
0
r2752 - in trunk/jaxx-demo/src/main/java/jaxx/demo: . component/jaxx/editor entities feature/databinding
by tchemit@users.nuiton.org 24 Nov '13
by tchemit@users.nuiton.org 24 Nov '13
24 Nov '13
Author: tchemit
Date: 2013-11-24 09:44:06 +0100 (Sun, 24 Nov 2013)
New Revision: 2752
Url: http://nuiton.org/projects/jaxx/repository/revisions/2752
Log:
improve jaxx demo code
Modified:
trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java
trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/NumberEditorDemoModel.java
trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoHandler.java
trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoModel.java
trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/TimeEditorDemoModel.java
trunk/jaxx-demo/src/main/java/jaxx/demo/entities/AbstractDemoBean.java
trunk/jaxx-demo/src/main/java/jaxx/demo/entities/Identity.java
trunk/jaxx-demo/src/main/java/jaxx/demo/entities/Model.java
trunk/jaxx-demo/src/main/java/jaxx/demo/feature/databinding/DefaultDemoUIModel.java
trunk/jaxx-demo/src/main/java/jaxx/demo/feature/databinding/DemoUIModel.java
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java 2013-11-24 08:43:43 UTC (rev 2751)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java 2013-11-24 08:44:06 UTC (rev 2752)
@@ -33,9 +33,9 @@
import org.jdesktop.beans.AbstractBean;
import org.nuiton.config.ApplicationConfig;
import org.nuiton.config.ArgumentsParserException;
+import org.nuiton.config.ConfigOptionDef;
import org.nuiton.util.Version;
import org.nuiton.util.VersionUtil;
-import org.nuiton.config.ConfigOptionDef;
import javax.swing.KeyStroke;
import java.awt.Color;
@@ -134,7 +134,7 @@
try {
applicationConfig.parse(args);
} catch (ArgumentsParserException e) {
- throw new IllegalStateException("Could not parse configuration",e);
+ throw new IllegalStateException("Could not parse configuration", e);
}
}
@@ -210,8 +210,8 @@
}
public boolean isFullScreen() {
- Boolean result = applicationConfig.getOptionAsBoolean(Option.FULL_SCREEN.key);
- return result != null && result;
+ boolean result = applicationConfig.getOptionAsBoolean(Option.FULL_SCREEN.key);
+ return result;
}
public Locale getLocale() {
@@ -254,9 +254,8 @@
}
public void setFullscreen(boolean fullscreen) {
- Object oldValue = null;
applicationConfig.setOption(Option.FULL_SCREEN.key, fullscreen + "");
- firePropertyChange(PROPERTY_FULLSCREEN, oldValue, fullscreen);
+ firePropertyChange(PROPERTY_FULLSCREEN, null, fullscreen);
}
public void setLocale(Locale newLocale) {
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/NumberEditorDemoModel.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/NumberEditorDemoModel.java 2013-11-24 08:43:43 UTC (rev 2751)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/NumberEditorDemoModel.java 2013-11-24 08:44:06 UTC (rev 2752)
@@ -25,29 +25,24 @@
package jaxx.demo.component.jaxx.editor;
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
+import org.jdesktop.beans.AbstractSerializableBean;
/**
* @author tchemit <chemit(a)codelutin.com>
* @since 1.5
*/
-public class NumberEditorDemoModel {
+public class NumberEditorDemoModel extends AbstractSerializableBean {
public static final String INTEGER_PROPERTY = "integerProperty";
public static final String FLOAT_PROPERTY = "floatProperty";
- protected PropertyChangeSupport p;
+ private static final long serialVersionUID = 1L;
protected int integerProperty;
protected float floatProperty;
- public NumberEditorDemoModel() {
- p = new PropertyChangeSupport(this);
- }
-
public float getFloatProperty() {
return floatProperty;
}
@@ -59,28 +54,12 @@
public void setFloatProperty(float floatProperty) {
float old = this.floatProperty;
this.floatProperty = floatProperty;
- p.firePropertyChange(FLOAT_PROPERTY, old, floatProperty);
+ firePropertyChange(FLOAT_PROPERTY, old, floatProperty);
}
public void setIntegerProperty(int integerProperty) {
int old = this.integerProperty;
this.integerProperty = integerProperty;
- p.firePropertyChange(INTEGER_PROPERTY, old, integerProperty);
+ firePropertyChange(INTEGER_PROPERTY, old, integerProperty);
}
-
- public void addPropertyChangeListener(PropertyChangeListener listener) {
- p.addPropertyChangeListener(listener);
- }
-
- public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- p.addPropertyChangeListener(propertyName, listener);
- }
-
- public void removePropertyChangeListener(PropertyChangeListener listener) {
- p.removePropertyChangeListener(listener);
- }
-
- public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- p.removePropertyChangeListener(propertyName, listener);
- }
}
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoHandler.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoHandler.java 2013-11-24 08:43:43 UTC (rev 2751)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoHandler.java 2013-11-24 08:44:06 UTC (rev 2752)
@@ -4,7 +4,7 @@
* Created on 11/22/13.
*
* @author Tony CHEMIT <chemit(a)codelutin.com>
- * @since 2.5.31
+ * @since 2.6
*/
public class SimpleTimeEditorDemoHandler {
}
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoModel.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoModel.java 2013-11-24 08:43:43 UTC (rev 2751)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoModel.java 2013-11-24 08:44:06 UTC (rev 2752)
@@ -33,7 +33,7 @@
* Model of a bean using the {@link SimpleTimeEditor}.
*
* @author Tony CHEMIT <chemit(a)codelutin.com>
- * @since 2.5.31
+ * @since 2.6
*/
public class SimpleTimeEditorDemoModel extends AbstractSerializableBean {
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/TimeEditorDemoModel.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/TimeEditorDemoModel.java 2013-11-24 08:43:43 UTC (rev 2751)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/TimeEditorDemoModel.java 2013-11-24 08:44:06 UTC (rev 2752)
@@ -25,9 +25,8 @@
package jaxx.demo.component.jaxx.editor;
import jaxx.runtime.swing.editor.TimeEditor;
+import org.jdesktop.beans.AbstractSerializableBean;
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
import java.util.Date;
/**
@@ -36,18 +35,14 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 2.2
*/
-public class TimeEditorDemoModel {
+public class TimeEditorDemoModel extends AbstractSerializableBean {
public static final String TIME_PROPERTY = "time";
- protected final PropertyChangeSupport p;
+ private static final long serialVersionUID = 1L;
protected Date time;
- public TimeEditorDemoModel() {
- p = new PropertyChangeSupport(this);
- }
-
public Date getTime() {
return time;
}
@@ -55,25 +50,7 @@
public void setTime(Date time) {
Date old = this.time;
this.time = time;
- p.firePropertyChange(TIME_PROPERTY, old, time);
+ firePropertyChange(TIME_PROPERTY, old, time);
}
- public void addPropertyChangeListener(PropertyChangeListener listener) {
- p.addPropertyChangeListener(listener);
- }
-
- public void addPropertyChangeListener(String propertyName,
- PropertyChangeListener listener) {
- p.addPropertyChangeListener(propertyName, listener);
- }
-
- public void removePropertyChangeListener(PropertyChangeListener listener) {
- p.removePropertyChangeListener(listener);
- }
-
- public void removePropertyChangeListener(String propertyName,
- PropertyChangeListener listener) {
- p.removePropertyChangeListener(propertyName, listener);
- }
-
}
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/entities/AbstractDemoBean.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/entities/AbstractDemoBean.java 2013-11-24 08:43:43 UTC (rev 2751)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/entities/AbstractDemoBean.java 2013-11-24 08:44:06 UTC (rev 2752)
@@ -24,9 +24,7 @@
*/
package jaxx.demo.entities;
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
-import java.io.Serializable;
+import org.jdesktop.beans.AbstractSerializableBean;
import static org.nuiton.i18n.I18n.n_;
@@ -36,7 +34,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 2.2
*/
-public abstract class AbstractDemoBean implements Serializable {
+public abstract class AbstractDemoBean extends AbstractSerializableBean {
static {
n_("jaxxdemo.common.id");
@@ -53,14 +51,10 @@
protected String image;
- protected final PropertyChangeSupport p;
-
public AbstractDemoBean() {
- p = new PropertyChangeSupport(this);
}
protected AbstractDemoBean(String id, String image) {
- this();
this.id = id;
this.image = image;
}
@@ -85,24 +79,4 @@
this.image = image;
firePropertyChange(PROPERTY_IMAGE, oldValue, image);
}
-
- public void addPropertyChangeListener(PropertyChangeListener listener) {
- p.addPropertyChangeListener(listener);
- }
-
- public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- p.addPropertyChangeListener(propertyName, listener);
- }
-
- public void removePropertyChangeListener(PropertyChangeListener listener) {
- p.removePropertyChangeListener(listener);
- }
-
- public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- p.removePropertyChangeListener(propertyName, listener);
- }
-
- protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
- p.firePropertyChange(propertyName, oldValue, newValue);
- }
}
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/entities/Identity.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/entities/Identity.java 2013-11-24 08:43:43 UTC (rev 2751)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/entities/Identity.java 2013-11-24 08:44:06 UTC (rev 2752)
@@ -25,12 +25,11 @@
package jaxx.demo.entities;
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
+import org.jdesktop.beans.AbstractSerializableBean;
+
import java.io.File;
-import java.io.Serializable;
-public class Identity implements Serializable {
+public class Identity extends AbstractSerializableBean {
private static final long serialVersionUID = 1L;
@@ -46,29 +45,7 @@
protected File dir = new File("/tmp");
- protected final PropertyChangeSupport p;
- public Identity() {
- p = new PropertyChangeSupport(this);
- }
-
- public void addPropertyChangeListener(PropertyChangeListener listener) {
- p.addPropertyChangeListener(listener);
- }
-
- public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- p.addPropertyChangeListener(propertyName, listener);
- }
-
- public void removePropertyChangeListener(PropertyChangeListener listener) {
- p.removePropertyChangeListener(listener);
- }
-
- public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- p.removePropertyChangeListener(propertyName, listener);
- }
-
-
public String getFirstName() {
return firstName;
}
@@ -96,36 +73,36 @@
public void setFirstName(String firstName) {
String oldFirstName = this.firstName;
this.firstName = firstName;
- p.firePropertyChange("firstName", oldFirstName, firstName);
+ firePropertyChange("firstName", oldFirstName, firstName);
}
public void setLastName(String lastName) {
String oldLastName = this.lastName;
this.lastName = lastName;
- p.firePropertyChange("lastName", oldLastName, lastName);
+ firePropertyChange("lastName", oldLastName, lastName);
}
public void setEmail(String email) {
String oldEmail = this.email;
this.email = email;
- p.firePropertyChange("email", oldEmail, email);
+ firePropertyChange("email", oldEmail, email);
}
public void setAge(int age) {
int oldAge = this.age;
this.age = age;
- p.firePropertyChange("age", oldAge, age);
+ firePropertyChange("age", oldAge, age);
}
public void setConfig(File config) {
File oldConfig = this.config;
this.config = config;
- p.firePropertyChange("config", oldConfig, config);
+ firePropertyChange("config", oldConfig, config);
}
public void setDir(File dir) {
File oldDir = this.dir;
this.dir = dir;
- p.firePropertyChange("dir", oldDir, dir);
+ firePropertyChange("dir", oldDir, dir);
}
}
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/entities/Model.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/entities/Model.java 2013-11-24 08:43:43 UTC (rev 2751)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/entities/Model.java 2013-11-24 08:44:06 UTC (rev 2752)
@@ -25,41 +25,18 @@
package jaxx.demo.entities;
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
+import org.jdesktop.beans.AbstractSerializableBean;
-public class Model {
+public class Model extends AbstractSerializableBean {
+ private static final long serialVersionUID = 1L;
+
protected String text = "text";
protected String text2 = "text2";
protected int ratio = 51;
-
- PropertyChangeSupport p;
-
- public Model() {
- p = new PropertyChangeSupport(this);
- }
-
- public void addPropertyChangeListener(PropertyChangeListener listener) {
- p.addPropertyChangeListener(listener);
- }
-
- public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- p.addPropertyChangeListener(propertyName, listener);
- }
-
- public void removePropertyChangeListener(PropertyChangeListener listener) {
- p.removePropertyChangeListener(listener);
- }
-
- public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- p.removePropertyChangeListener(propertyName, listener);
- }
-
-
public String getText() {
return text;
}
@@ -75,18 +52,18 @@
public void setText(String text) {
String oldText = this.text;
this.text = text;
- p.firePropertyChange("text", oldText, text);
+ firePropertyChange("text", oldText, text);
}
public void setText2(String text2) {
String oldText2 = this.text2;
this.text2 = text2;
- p.firePropertyChange("text2", oldText2, text2);
+ firePropertyChange("text2", oldText2, text2);
}
public void setRatio(int ratio) {
int oldRatio = this.ratio;
this.ratio = ratio;
- p.firePropertyChange("ratio", oldRatio, ratio);
+ firePropertyChange("ratio", oldRatio, ratio);
}
}
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/feature/databinding/DefaultDemoUIModel.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/feature/databinding/DefaultDemoUIModel.java 2013-11-24 08:43:43 UTC (rev 2751)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/feature/databinding/DefaultDemoUIModel.java 2013-11-24 08:44:06 UTC (rev 2752)
@@ -26,10 +26,9 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.jdesktop.beans.AbstractSerializableBean;
import javax.swing.JToggleButton;
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
import java.io.File;
/**
@@ -37,13 +36,12 @@
*
* @author tchemit <chemit(a)codelutin.com>
* @version $Revision$
- * <p/>
- * Mise a jour: $Date$ par :
- * $Author$
*/
-public class DefaultDemoUIModel implements DemoUIModel {
+public class DefaultDemoUIModel extends AbstractSerializableBean implements DemoUIModel {
+ private static final long serialVersionUID = 1L;
+
protected File file;
protected File file1;
@@ -64,8 +62,6 @@
public static final String PROPERTY_FILE = "file";
- protected final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
-
protected static final Log log = LogFactory.getLog(DefaultDemoUIModel.class);
/*---------------------------------------------------------------------------------*/
@@ -141,30 +137,4 @@
firePropertyChange(PROPERTY_T1, oldValue, newValue);
}
- @Override
- public void firePropertyChange(String name, Object oldValue, Object newValue) {
- pcs.firePropertyChange(name, oldValue, newValue);
- }
-
- @Override
- public void addPropertyChangeListener(PropertyChangeListener listener) {
- pcs.addPropertyChangeListener(listener);
- }
-
- @Override
- public void addPropertyChangeListener(String property, PropertyChangeListener listener) {
- pcs.addPropertyChangeListener(property, listener);
- }
-
- @Override
- public void removePropertyChangeListener(PropertyChangeListener listener) {
- pcs.removePropertyChangeListener(listener);
- }
-
- @Override
- public void removePropertyChangeListener(String property, PropertyChangeListener listener) {
- pcs.removePropertyChangeListener(property, listener);
- }
-
-
}
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/feature/databinding/DemoUIModel.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/feature/databinding/DemoUIModel.java 2013-11-24 08:43:43 UTC (rev 2751)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/feature/databinding/DemoUIModel.java 2013-11-24 08:44:06 UTC (rev 2752)
@@ -55,16 +55,16 @@
void setFile(File newValue);
- /**
- * All <code>JAXXObject</code> implements are capable of broadcasting <code>PropertyChangeEvent</code>, and
- * furthermore (for technical reasons) must allow code in outside packages, specifically the JAXX runtime,
- * to trigger these events.
- *
- * @param name the name of the property which changed
- * @param oldValue the old value of the property
- * @param newValue the new value of the property
- */
- void firePropertyChange(String name, Object oldValue, Object newValue);
+// /**
+// * All <code>JAXXObject</code> implements are capable of broadcasting <code>PropertyChangeEvent</code>, and
+// * furthermore (for technical reasons) must allow code in outside packages, specifically the JAXX runtime,
+// * to trigger these events.
+// *
+// * @param name the name of the property which changed
+// * @param oldValue the old value of the property
+// * @param newValue the new value of the property
+// */
+// void firePropertyChange(String name, Object oldValue, Object newValue);
/**
* Register a general {@link PropertyChangeListener}.
1
0
r2751 - in trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor: . gis
by tchemit@users.nuiton.org 24 Nov '13
by tchemit@users.nuiton.org 24 Nov '13
24 Nov '13
Author: tchemit
Date: 2013-11-24 09:43:43 +0100 (Sun, 24 Nov 2013)
New Revision: 2751
Url: http://nuiton.org/projects/jaxx/repository/revisions/2751
Log:
fixes #2929: Introduce some coordinate editors
Added:
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinate.java
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditor.css
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditor.jaxx
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorHandler.java
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorModel.java
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinate.java
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditor.css
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditor.jaxx
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorHandler.java
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorModel.java
Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinate.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinate.java (rev 0)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinate.java 2013-11-24 08:43:43 UTC (rev 2751)
@@ -0,0 +1,270 @@
+package jaxx.runtime.swing.editor.gis;
+
+import org.jdesktop.beans.AbstractSerializableBean;
+
+/**
+ * Geo coordinate in degree decimal, minute format.
+ * <p/>
+ * Created on 10/23/13.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.6
+ */
+public class DmdCoordinate extends AbstractSerializableBean {
+
+ 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_DECIMAL = "decimal";
+
+ protected boolean sign;
+
+ protected Integer degree;
+
+ protected Integer minute;
+
+ protected Integer decimal;
+
+ public static DmdCoordinate empty() {
+ DmdCoordinate r = new DmdCoordinate();
+ return r;
+ }
+
+ /**
+ * Methode statique de fabrique de position a partir d'une valeur du format
+ * decimal.
+ * <p/>
+ * Note : Si la valeur (au format decimal) vaut <code>null</code>, alors on
+ * reinitialise les composants de la position a <code>null</code> et la
+ * methode {@link #isNull()} vaudra alors {@code true}.
+ *
+ * @param decimal la valeur au format decimal
+ * @return une nouvelle instance de position convertie
+ */
+ public static DmdCoordinate valueOf(Float decimal) {
+ DmdCoordinate r = new DmdCoordinate();
+ r.fromDecimal(decimal);
+ return r;
+ }
+
+ /**
+ * Methode statique de fabrique de position a partir d'une valeur du format
+ * degre décimale minute.
+ *
+ * @param d la valeur des degres
+ * @param m la valeur des minutes
+ * @param dc la valeur des décimales de minutes
+ * @return une nouvelle instance de position convertie
+ */
+ public static DmdCoordinate valueOf(boolean sign, int d, int m, int dc) {
+ DmdCoordinate r = new DmdCoordinate();
+ r.setSign(sign);
+ r.setDegree(d);
+ r.setMinute(m);
+ r.setDecimal(dc);
+ return r;
+ }
+
+ public boolean isSign() {
+ return sign;
+ }
+
+ public Integer getDegree() {
+ return degree;
+ }
+
+ public Integer getMinute() {
+ return minute;
+ }
+
+ public Integer getDecimal() {
+ return decimal;
+ }
+
+ public void setSign(boolean sign) {
+ Object oldValue = isSign();
+ this.sign = sign;
+ firePropertyChange(PROPERTY_SIGN, oldValue, sign);
+ }
+
+ public void setDegree(Integer degree) {
+ Object oldValue = getDegree();
+ this.degree = degree;
+ firePropertyChange(PROPERTY_DEGREE, oldValue, degree);
+ }
+
+ public void setMinute(Integer minute) {
+ Object oldValue = getMinute();
+ this.minute = minute;
+ firePropertyChange(PROPERTY_MINUTE, oldValue, minute);
+ }
+
+ public void setDecimal(Integer decimal) {
+ Object oldValue = getDecimal();
+ this.decimal = decimal;
+ firePropertyChange(PROPERTY_DECIMAL, oldValue, decimal);
+ }
+
+ /**
+ * @return {@code true} si aucune composante n'est renseignée,
+ * {@code false} autrement.
+ */
+ public boolean isNull() {
+ return degree == null && minute == null && decimal == null;
+ }
+
+ public boolean isDegreeNull() {
+ return degree == null || degree == 0;
+ }
+
+ public boolean isMinuteNull() {
+ return minute == null || minute == 0;
+ }
+
+ public boolean isDecimalNull() {
+ return decimal == null || decimal == 0;
+ }
+
+ /**
+ * Mets a jour les composants de la position a partir d'une valeur decimal.
+ * <p/>
+ * Note : Si la valeur (au format decimal) vaut <code>null</code>, alors on
+ * reinitialise les composants de la position a <code>null</code> et la
+ * methode {@link #isNull()} vaudra alors {@code true}.
+ *
+ * @param decimalValue la valeur decimale a convertir (qui peut etre nulle).
+ */
+ public void fromDecimal(Float decimalValue) {
+ Integer d = null;
+ Integer m = null;
+ Integer dc = null;
+ boolean si = false;
+ if (decimalValue != null) {
+ si = decimalValue < 0;
+
+ float absDecimal = Math.abs(decimalValue);
+
+ d = (int) (Math.round(absDecimal + 0.5) - 1);
+ int rest = Math.round(100 * 60.0f * (absDecimal - d));
+ if (rest > 0) {
+ m = rest / 100;
+ dc = (rest - m * 100);
+
+ // clean not used values
+ if (m == 0) {
+ m = null;
+ }
+ if (dc == 0) {
+ dc = null;
+ }
+ }
+ if (d == 0) {
+ d = null;
+ }
+ }
+
+ degree = d;
+ minute = m;
+ decimal = dc;
+ sign = si;
+ }
+
+ 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 Integer getSignedDegree() {
+ Integer result = null;
+ if (!isDegreeNull()) {
+ result = degree;
+ if (isSign()) {
+ result *= -1;
+ }
+ }
+ return result;
+ }
+
+ public int getNotNullDegree() {
+ return isDegreeNull() ? 0 : degree;
+ }
+
+ public int getNotNullMinute() {
+ return isMinuteNull() ? 0 : minute;
+ }
+
+ public int getNotNullDecimal() {
+ return isDecimalNull() ? 0 : decimal;
+ }
+
+ public boolean isLatitudeDegreeValid() {
+ boolean result = isDegreeValid(false);
+ return result;
+ }
+
+ public boolean isLongitudeDegreeValid() {
+ boolean result = isDegreeValid(true);
+ return result;
+ }
+
+ public boolean isMinuteValid() {
+ boolean result = true;
+ if (!isMinuteNull()) {
+ if (minute == 60) {
+
+ // can not have decimal
+ result = isDecimalNull();
+ } else {
+ result = 0 <= minute && minute < 60;
+ }
+ }
+ return result;
+ }
+
+ public boolean isDecimalValid() {
+ boolean result = isDecimalNull() || (0 <= decimal && decimal < 100);
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "DmdCoordinateComponent{" +
+ "sign=" + sign +
+ ", degree=" + degree +
+ ", minute=" + minute +
+ ", decimal=" + decimal +
+ '}';
+ }
+
+ protected boolean isDegreeValid(boolean longitude) {
+ boolean result = true;
+ if (!isDegreeNull()) {
+ int bound = longitude ? 180 : 90;
+ if (bound == degree) {
+
+ // can not have minute nor decimal
+ result = isMinuteNull() && isDecimalNull();
+ } else {
+ result = 0 <= degree && degree < bound;
+ }
+ }
+ return result;
+ }
+
+}
Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinate.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditor.css
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditor.css (rev 0)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditor.css 2013-11-24 08:43:43 UTC (rev 2751)
@@ -0,0 +1,17 @@
+#toolbarLeft {
+ floatable:false;
+ borderPainted:false;
+ visible:{isShowReset()};
+}
+
+#resetButton {
+ actionIcon:"combobox-reset";
+ toolTipText: {getShowResetTip()};
+ focusable:false;
+ focusPainted:false;
+ enabled:{isEnabled()};
+}
+
+#editor {
+ enabled:{isEnabled()};
+}
\ No newline at end of file
Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditor.css
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditor.jaxx
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditor.jaxx (rev 0)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditor.jaxx 2013-11-24 08:43:43 UTC (rev 2751)
@@ -0,0 +1,38 @@
+<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() { handler.init(); }
+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 setLongitudeEditor(boolean longitudeEditor) { model.setLongitudeEditor(longitudeEditor); }
+public void setValue(DmdCoordinate value) { handler.setValue(value, false); }
+]]>
+ </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>
\ No newline at end of file
Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorHandler.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorHandler.java (rev 0)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorHandler.java 2013-11-24 08:43:43 UTC (rev 2751)
@@ -0,0 +1,333 @@
+package jaxx.runtime.swing.editor.gis;
+
+import com.google.common.base.Preconditions;
+import jaxx.runtime.swing.editor.bean.BeanUIUtil;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.swing.JFormattedTextField;
+import javax.swing.text.DefaultFormatterFactory;
+import javax.swing.text.MaskFormatter;
+import java.awt.event.KeyEvent;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.lang.reflect.Method;
+import java.text.ParseException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Created on 10/16/13.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.6
+ */
+public class DmdCoordinateEditorHandler {
+
+ /** Logger. */
+ private static final Log log =
+ LogFactory.getLog(DmdCoordinateEditorHandler.class);
+
+ protected static final Pattern VALUE_PATTERN = Pattern.compile("(.*)°(.*)'(.*)");
+
+ private final DmdCoordinateEditor ui;
+
+ protected Method signMutator;
+
+ protected Method degreMutator;
+
+ protected Method minuteMutator;
+
+ protected Method decimalMutator;
+
+ protected DefaultFormatterFactory unsignedFactory;
+
+ protected DefaultFormatterFactory signedFactory;
+
+ protected boolean valueIsAdjusting;
+
+ protected boolean valueModelIsAdjusting;
+
+ public DmdCoordinateEditorHandler(DmdCoordinateEditor ui) {
+ this.ui = ui;
+ }
+
+ public void init() {
+
+ 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 = BeanUIUtil.getMutator(bean, model.getPropertySign());
+ Preconditions.checkNotNull(signMutator, "could not find mutator for " + model.getPropertySign());
+
+ degreMutator = BeanUIUtil.getMutator(bean, model.getPropertyDegree());
+ Preconditions.checkNotNull(degreMutator, "could not find mutator for " + model.getPropertyDegree());
+
+ minuteMutator = BeanUIUtil.getMutator(bean, model.getPropertyMinute());
+ Preconditions.checkNotNull(minuteMutator, "could not find mutator for " + model.getPropertyMinute());
+
+ decimalMutator = BeanUIUtil.getMutator(bean, model.getPropertyDecimal());
+ Preconditions.checkNotNull(decimalMutator, "could not find mutator for " + model.getPropertyDecimal());
+
+ MaskFormatter unsignedFormatter;
+ try {
+
+ String pattern = model.getMaskFormatterPattern();
+ unsignedFormatter = new MaskFormatter(pattern);
+ unsignedFormatter.setValidCharacters(" 01234567890");
+ } catch (ParseException e) {
+ // can't happen here
+ throw new RuntimeException(e);
+ }
+ unsignedFactory = new DefaultFormatterFactory(unsignedFormatter);
+
+ MaskFormatter signedFormatter;
+ try {
+
+ String pattern = model.getMaskFormatterPattern();
+ signedFormatter = new MaskFormatter("-" + pattern);
+ signedFormatter.setValidCharacters(" 01234567890");
+ } catch (ParseException e) {
+ // can't happen here
+ throw new RuntimeException(e);
+ }
+ signedFactory = new DefaultFormatterFactory(signedFormatter);
+
+ JFormattedTextField editor = ui.getEditor();
+ editor.setFormatterFactory(unsignedFactory);
+ editor.setFocusLostBehavior(JFormattedTextField.COMMIT);
+
+ // When editor changes his value, propagate it to model
+ editor.addPropertyChangeListener("value", new PropertyChangeListener() {
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ String newValue = (String) evt.getNewValue();
+ if (log.isDebugEnabled()) {
+ log.debug("Value has changed: " + newValue);
+ }
+ DmdCoordinate value = null;
+ if (newValue != null) {
+
+ Matcher matcher = VALUE_PATTERN.matcher(newValue);
+
+ 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) ? 0 : Integer.valueOf(degresStr);
+ Integer minutes = minutesStr.isEmpty() ? 0 : Integer.valueOf(minutesStr);
+ Integer decimal = decimalesStr.isEmpty() ? 0 : Integer.valueOf(decimalesStr);
+
+ boolean signed = degre < 0;
+ value =
+ DmdCoordinate.valueOf(signed,
+ Math.abs(degre),
+ minutes,
+ decimal);
+ }
+ }
+ model.setValue(value);
+ }
+ });
+
+ // 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;
+ }
+
+ String signStr = "";
+ String degreeStr = "";
+ String minuteStr = "";
+ String decimalStr = "";
+
+ if (value != null) {
+
+ boolean sign = value.isSign();
+ signStr = sign ? "-" : "";
+
+ Integer degree = value.getDegree();
+ degreeStr = degree == null ? "" : degree.toString();
+
+ Integer minute = value.getMinute();
+ minuteStr = minute == null ? "" : minute.toString();
+
+ Integer decimal = value.getDecimal();
+ decimalStr = decimal == null ? "" : decimal.toString();
+ }
+
+ DmdCoordinateEditorModel model = ui.getModel();
+
+ String stringPattern = model.getStringPattern();
+ String valueStr = String.format(
+ stringPattern,
+ signStr,
+ StringUtils.leftPad(degreeStr, model.isLongitudeEditor() ? 3 : 2, ' '),
+ StringUtils.leftPad(minuteStr, 2, ' '),
+ StringUtils.leftPad(decimalStr, 2, ' '));
+
+ valueIsAdjusting = !pushToModel;
+
+ try {
+ ui.getEditor().setValue(valueStr);
+ } finally {
+ valueIsAdjusting = false;
+ }
+ }
+
+ public void resetEditor() {
+ // set null value to model
+ setValue(null, true);
+
+ // use back unsigned format
+ ui.getEditor().setFormatterFactory(unsignedFactory);
+ }
+
+ 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 + ")");
+ }
+
+ String newValue = null;
+ DefaultFormatterFactory newFactory = null;
+ if (keyChar == '-') {
+
+ // try to switch unsigned to signed
+
+ if (unsignedFactory == source.getFormatterFactory()) {
+
+ // switch to signed
+ if (log.isDebugEnabled()) {
+ log.debug("Switch to signed");
+ }
+ newFactory = signedFactory;
+
+ try {
+ source.commitEdit();
+ } catch (ParseException e1) {
+ // ignore it
+ }
+
+ newValue = "-" + source.getValue();
+
+ } else {
+ // switch to unsigned
+
+ if (log.isDebugEnabled()) {
+ log.debug("Switch to unsigned");
+ }
+ newFactory = unsignedFactory;
+
+ try {
+ source.commitEdit();
+ } catch (ParseException e1) {
+ // ignore it
+ }
+
+ newValue = ((String) source.getValue()).substring(1);
+ }
+ } else {
+ try {
+ source.commitEdit();
+ } catch (ParseException e1) {
+ // ignore it
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("Key pressed: newValue " + source.getValue());
+ }
+ }
+
+ if (newFactory != null) {
+
+ // consume event (prevent any side-effects)
+ e.consume();
+
+ if (log.isDebugEnabled()) {
+ log.debug("Key pressed: newValue " + newValue);
+ }
+ source.setFormatterFactory(newFactory);
+ source.setValue(newValue);
+
+ if (unsignedFactory == newFactory) {
+
+ // remove a sign
+ caretPosition--;
+ } else {
+
+ // add a sign
+ caretPosition++;
+ }
+
+ source.setCaretPosition(caretPosition);
+ }
+ }
+
+ 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);
+ }
+ }
+ }
+ }
+}
Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorHandler.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorModel.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorModel.java (rev 0)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorModel.java 2013-11-24 08:43:43 UTC (rev 2751)
@@ -0,0 +1,127 @@
+package jaxx.runtime.swing.editor.gis;
+
+import java.io.Serializable;
+
+/**
+ * Created on 10/16/13.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @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";
+
+ public static final String PROPERTY_LONGITUDE_EDITOR = "longitudeEditor";
+
+ 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;
+
+ /**
+ * {@code true} if longitude editor, {@code false} for latitude editor.
+ */
+ protected boolean longitudeEditor;
+
+ 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 boolean isLongitudeEditor() {
+ return longitudeEditor;
+ }
+
+ public void setLongitudeEditor(boolean longitudeEditor) {
+ Object oldValue = isLongitudeEditor();
+ this.longitudeEditor = longitudeEditor;
+ firePropertyChange(PROPERTY_BEAN, oldValue, longitudeEditor);
+ }
+
+ 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 getMaskFormatterPattern() {
+ String pattern = "**°**''**";
+ if (isLongitudeEditor()) {
+ // add one more degre
+ pattern = "*" + pattern;
+ }
+ return pattern;
+ }
+
+ public String getStringPattern() {
+ String pattern = "%s%s°%s'%s";
+ return pattern;
+ }
+}
Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmdCoordinateEditorModel.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinate.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinate.java (rev 0)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinate.java 2013-11-24 08:43:43 UTC (rev 2751)
@@ -0,0 +1,300 @@
+package jaxx.runtime.swing.editor.gis;
+
+import org.jdesktop.beans.AbstractSerializableBean;
+
+/**
+ * Geo coordinate in degree, minute, second format.
+ * <p/>
+ * Created on 10/23/13.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.6
+ */
+public class DmsCoordinate extends AbstractSerializableBean {
+
+ private static final long serialVersionUID = 1L;
+
+ public static final String PROPERTY_SIGN = "sign";
+
+ public static final String PROPERTY_DEGREE = "degree";
+
+ public static final String PROPERTY_MINUTE = "minute";
+
+ public static final String PROPERTY_SECOND = "second";
+
+ protected boolean sign;
+
+ protected Integer degree;
+
+ protected Integer minute;
+
+ protected Integer second;
+
+ public static DmsCoordinate empty() {
+ DmsCoordinate r = new DmsCoordinate();
+ return r;
+ }
+
+ /**
+ * Methode statique de fabrique de position a partir d'une valeur du format
+ * decimal.
+ * <p/>
+ * Note : Si la valeur (au format decimal) vaut <code>null</code>, alors on
+ * reinitialise les composants de la position a <code>null</code> et la
+ * methode {@link #isNull()} vaudra alors {@code true}.
+ *
+ * @param decimal la valeur au format decimal
+ * @return une nouvelle instance de position convertie
+ */
+ public static DmsCoordinate valueOf(Float decimal) {
+ DmsCoordinate r = new DmsCoordinate();
+ r.fromDecimal(decimal);
+ return r;
+ }
+
+ /**
+ * Methode statique de fabrique de position a partir d'une valeur du format
+ * degre-minute-seconde.
+ *
+ * @param d la valeur des degres
+ * @param m la valeur des minutes
+ * @param s la valeur des secondes
+ * @return une nouvelle instance de position convertie
+ */
+ public static DmsCoordinate valueOf(boolean sign, int d, int m, int s) {
+ DmsCoordinate r = new DmsCoordinate();
+ r.setSign(sign);
+ r.setDegree(d);
+ r.setMinute(m);
+ r.setSecond(s);
+ return r;
+ }
+
+ public boolean isSign() {
+ return sign;
+ }
+
+ public Integer getDegree() {
+ return degree;
+ }
+
+ public Integer getMinute() {
+ return minute;
+ }
+
+ public Integer getSecond() {
+ return second;
+ }
+
+ public void setSign(boolean sign) {
+ Object oldValue = isSign();
+ this.sign = sign;
+ firePropertyChange(PROPERTY_SIGN, oldValue, sign);
+ }
+
+ public void setDegree(Integer degree) {
+ Object oldValue = getDegree();
+ this.degree = degree;
+ firePropertyChange(PROPERTY_DEGREE, oldValue, degree);
+ }
+
+ public void setMinute(Integer minute) {
+ Object oldValue = getMinute();
+ this.minute = minute;
+ firePropertyChange(PROPERTY_MINUTE, oldValue, minute);
+ }
+
+ public void setSecond(Integer second) {
+ Object oldValue = getSecond();
+ this.second = second;
+ firePropertyChange(PROPERTY_SECOND, oldValue, second);
+ }
+
+ public boolean isDegreeNull() {
+ return degree == null || degree == 0;
+ }
+
+ public boolean isMinuteNull() {
+ return minute == null || minute == 0;
+ }
+
+ public boolean isSecondNull() {
+ return second == null || second == 0;
+ }
+
+ /**
+ * @return {@code true} si aucune composante n'est renseignée,
+ * {@code false} autrement.
+ */
+ public boolean isNull() {
+ return degree == null && minute == null && second == null;
+ }
+
+ /**
+ * Mets a jour les composants de la position a partir d'une valeur decimal.
+ * <p/>
+ * Note : Si la valeur (au format decimal) vaut <code>null</code>, alors on
+ * reinitialise les composants de la position a <code>null</code> et la
+ * methode {@link #isNull()} vaudra alors {@code true}.
+ *
+ * @param decimal la valeur decimale a convertir (qui peut etre nulle).
+ */
+ public void fromDecimal(Float decimal) {
+ Integer d = null;
+ Integer m = null;
+ Integer s = null;
+ boolean si = false;
+ if (decimal != null) {
+ si = decimal < 0;
+
+ decimal = Math.abs(decimal);
+ int remain = 0;
+
+ d = (int) (Math.round(decimal + 0.5) - 1);
+ m = 0;
+ s = 0;
+ decimal = 60.0f * (decimal - d);
+ if (decimal > 0) {
+ m = (int) (Math.round(decimal + 0.5) - 1);
+ decimal = 60 * (decimal - m);
+ if (decimal > 0) {
+ s = (int) (Math.round(decimal + 0.5) - 1);
+ remain = (int) (10 * (decimal - s));
+ }
+ }
+ if (remain > 9) {
+ s++;
+ }
+ if (s == 60) {
+ m++;
+ s = 0;
+ }
+ if (m == 60) {
+ d++;
+ m = 0;
+ }
+
+ // clean not used values
+ if (m == 0) {
+ m = null;
+ }
+ if (s == 0) {
+ s = null;
+ }
+ }
+
+ if (d != null && d == 0) {
+ d = null;
+ }
+ degree = d;
+ minute = m;
+ second = s;
+ sign = si;
+
+ }
+
+ 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 Integer getSignedDegree() {
+ Integer result = null;
+ if (!isDegreeNull()) {
+ result = degree;
+ if (isSign()) {
+ result *= -1;
+ }
+ }
+ return result;
+ }
+
+ public int getNotNullDegree() {
+ return isDegreeNull() ? 0 : degree;
+ }
+
+ public int getNotNullMinute() {
+ return isMinuteNull() ? 0 : minute;
+ }
+
+
+ public int getNotNullSecond() {
+ return isSecondNull() ? 0 : second;
+ }
+
+ public boolean isLatitudeDegreeValid() {
+ boolean result = isDegreeValid(false);
+ return result;
+ }
+
+ public boolean isLongitudeDegreeValid() {
+ boolean result = isDegreeValid(true);
+ return result;
+ }
+
+ public boolean isMinuteValid() {
+ boolean result = true;
+ if (!isMinuteNull()) {
+ if (60 == minute) {
+
+ // check minute and second are null
+ result = isSecondNull();
+ } else {
+ result = 0 <= minute && minute < 60;
+ }
+ }
+ return result;
+ }
+
+ public boolean isSecondValid() {
+ boolean result = isSecondNull() || (0 <= second && second < 60);
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "DmsCoordinateComponent{" +
+ "sign=" + sign +
+ ", degree=" + degree +
+ ", minute=" + minute +
+ ", second=" + second +
+ '}';
+ }
+
+ protected boolean isDegreeValid(boolean longitude) {
+ boolean result = true;
+ if (!isDegreeNull()) {
+ int bound = longitude ? 180 : 90;
+ if (bound == degree) {
+
+ // check minute and second are null
+ result = isMinuteNull() && isSecondNull();
+ } else {
+ result = degree < bound;
+ }
+ }
+ return result;
+ }
+}
Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinate.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditor.css
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditor.css (rev 0)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditor.css 2013-11-24 08:43:43 UTC (rev 2751)
@@ -0,0 +1,17 @@
+#toolbarLeft {
+ floatable:false;
+ borderPainted:false;
+ visible:{isShowReset()};
+}
+
+#resetButton {
+ actionIcon:"combobox-reset";
+ toolTipText: {getShowResetTip()};
+ focusable:false;
+ focusPainted:false;
+ enabled:{isEnabled()};
+}
+
+#editor {
+ enabled:{isEnabled()};
+}
\ No newline at end of file
Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditor.css
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditor.jaxx
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditor.jaxx (rev 0)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditor.jaxx 2013-11-24 08:43:43 UTC (rev 2751)
@@ -0,0 +1,39 @@
+<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() { handler.init(); }
+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 setLongitudeEditor(boolean longitudeEditor) { model.setLongitudeEditor(longitudeEditor); }
+public void setValue(DmsCoordinate value) { handler.setValue(value, false); }
+]]>
+ </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>
\ No newline at end of file
Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorHandler.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorHandler.java (rev 0)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorHandler.java 2013-11-24 08:43:43 UTC (rev 2751)
@@ -0,0 +1,332 @@
+package jaxx.runtime.swing.editor.gis;
+
+import com.google.common.base.Preconditions;
+import jaxx.runtime.swing.editor.bean.BeanUIUtil;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.swing.JFormattedTextField;
+import javax.swing.text.DefaultFormatterFactory;
+import javax.swing.text.MaskFormatter;
+import java.awt.event.KeyEvent;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.lang.reflect.Method;
+import java.text.ParseException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Created on 10/16/13.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 2.6
+ */
+public class DmsCoordinateEditorHandler {
+
+ /** Logger. */
+ private static final Log log =
+ LogFactory.getLog(DmsCoordinateEditorHandler.class);
+
+ protected static final Pattern VALUE_PATTERN =
+ Pattern.compile("(.*)°(.*)'(.*)''");
+
+ private final DmsCoordinateEditor ui;
+
+ protected Method signMutator;
+
+ protected Method degreMutator;
+
+ protected Method minuteMutator;
+
+ protected Method secondMutator;
+
+ protected DefaultFormatterFactory unsignedFactory;
+
+ protected DefaultFormatterFactory signedFactory;
+
+ protected boolean valueIsAdjusting;
+
+ protected boolean valueModelIsAdjusting;
+
+ public DmsCoordinateEditorHandler(DmsCoordinateEditor ui) {
+ this.ui = ui;
+ }
+
+ public void init() {
+
+ 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 = BeanUIUtil.getMutator(bean, model.getPropertySign());
+ Preconditions.checkNotNull(signMutator, "could not find mutator for " + model.getPropertySign());
+
+ degreMutator = BeanUIUtil.getMutator(bean, model.getPropertyDegree());
+ Preconditions.checkNotNull(degreMutator, "could not find mutator for " + model.getPropertyDegree());
+
+ minuteMutator = BeanUIUtil.getMutator(bean, model.getPropertyMinute());
+ Preconditions.checkNotNull(minuteMutator, "could not find mutator for " + model.getPropertyMinute());
+
+ secondMutator = BeanUIUtil.getMutator(bean, model.getPropertySecond());
+ Preconditions.checkNotNull(secondMutator, "could not find mutator for " + model.getPropertySecond());
+
+ MaskFormatter unsignedFormatter;
+ try {
+
+ String pattern = model.getMaskFormatterPattern();
+ unsignedFormatter = new MaskFormatter(pattern);
+ unsignedFormatter.setValidCharacters(" 01234567890");
+ } catch (ParseException e) {
+ // can't happen here
+ throw new RuntimeException(e);
+ }
+ unsignedFactory = new DefaultFormatterFactory(unsignedFormatter);
+
+ MaskFormatter signedFormatter;
+ try {
+
+ String pattern = model.getMaskFormatterPattern();
+ signedFormatter = new MaskFormatter("-" + pattern);
+ signedFormatter.setValidCharacters(" 01234567890");
+ } catch (ParseException e) {
+ // can't happen here
+ throw new RuntimeException(e);
+ }
+ signedFactory = new DefaultFormatterFactory(signedFormatter);
+
+ JFormattedTextField editor = ui.getEditor();
+ editor.setFormatterFactory(unsignedFactory);
+ editor.setFocusLostBehavior(JFormattedTextField.COMMIT);
+
+ // When editor changes his value, propagate it to model
+ editor.addPropertyChangeListener("value", new PropertyChangeListener() {
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ String newValue = (String) evt.getNewValue();
+ if (log.isDebugEnabled()) {
+ log.debug("Value has changed: " + newValue);
+ }
+ DmsCoordinate value = null;
+ if (newValue != null) {
+
+ Matcher matcher = VALUE_PATTERN.matcher(newValue);
+
+ 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) ? 0 : Integer.valueOf(degresStr);
+ Integer minutes = minutesStr.isEmpty() ? 0 : Integer.valueOf(minutesStr);
+ Integer seconds = secondsStr.isEmpty() ? 0 : Integer.valueOf(secondsStr);
+
+ boolean signed = degre < 0;
+ value =
+ DmsCoordinate.valueOf(signed,
+ Math.abs(degre),
+ minutes,
+ seconds);
+ }
+ }
+ model.setValue(value);
+ }
+ });
+
+ // 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;
+ }
+
+ String signStr = "";
+ String degreeStr = "";
+ String minuteStr = "";
+ String secondStr = "";
+ if (value != null) {
+
+ boolean sign = value.isSign();
+ signStr = sign ? "-" : "";
+
+ Integer degree = value.getDegree();
+ degreeStr = degree == null ? "" : degree.toString();
+
+ Integer minute = value.getMinute();
+ minuteStr = minute == null ? "" : minute.toString();
+
+ Integer second = value.getSecond();
+ secondStr = second == null ? "" : second.toString();
+ }
+
+ DmsCoordinateEditorModel model = ui.getModel();
+ String stringPattern = model.getStringPattern();
+ String valueStr = String.format(
+ stringPattern,
+ signStr,
+ StringUtils.leftPad(degreeStr, model.isLongitudeEditor() ? 3 : 2, ' '),
+ StringUtils.leftPad(minuteStr, 2, ' '),
+ StringUtils.leftPad(secondStr, 2, ' '));
+
+ valueIsAdjusting = !pushToModel;
+
+ try {
+ ui.getEditor().setValue(valueStr);
+ } finally {
+ valueIsAdjusting = false;
+ }
+ }
+
+ public void resetEditor() {
+ // set null value to model
+ setValue(null, true);
+
+ // use back unsigned format
+ ui.getEditor().setFormatterFactory(unsignedFactory);
+ }
+
+ 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 + ")");
+ }
+
+ String newValue = null;
+ DefaultFormatterFactory newFactory = null;
+ if (keyChar == '-') {
+
+ // try to switch unsigned to signed
+
+ if (unsignedFactory == source.getFormatterFactory()) {
+
+ // switch to signed
+ if (log.isDebugEnabled()) {
+ log.debug("Switch to signed");
+ }
+ newFactory = signedFactory;
+
+ try {
+ source.commitEdit();
+ } catch (ParseException e1) {
+ // ignore it
+ }
+
+ newValue = "-" + source.getValue();
+
+ } else {
+ // switch to unsigned
+
+ if (log.isDebugEnabled()) {
+ log.debug("Switch to unsigned");
+ }
+ newFactory = unsignedFactory;
+
+ try {
+ source.commitEdit();
+ } catch (ParseException e1) {
+ // ignore it
+ }
+
+ newValue = ((String) source.getValue()).substring(1);
+ }
+ } else {
+ try {
+ source.commitEdit();
+ } catch (ParseException e1) {
+ // ignore it
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("Key pressed: newValue " + source.getValue());
+ }
+ }
+
+ if (newFactory != null) {
+
+ // consume event (prevent any side-effects)
+ e.consume();
+
+
+ if (log.isDebugEnabled()) {
+ log.debug("Key pressed: newValue " + newValue);
+ }
+ source.setFormatterFactory(newFactory);
+ source.setValue(newValue);
+
+ if (unsignedFactory == newFactory) {
+
+ // remove a sign
+ caretPosition--;
+ } else {
+
+ // add a sign
+ caretPosition++;
+ }
+
+ source.setCaretPosition(caretPosition);
+ }
+ }
+
+ 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);
+ }
+ }
+ }
+ }
+}
Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorHandler.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorModel.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorModel.java (rev 0)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorModel.java 2013-11-24 08:43:43 UTC (rev 2751)
@@ -0,0 +1,127 @@
+package jaxx.runtime.swing.editor.gis;
+
+import java.io.Serializable;
+
+/**
+ * Created on 10/16/13.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @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";
+
+ public static final String PROPERTY_LONGITUDE_EDITOR = "longitudeEditor";
+
+ 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;
+
+ /**
+ * {@code true} if longitude editor, {@code false} for latitude editor.
+ */
+ protected boolean longitudeEditor;
+
+ 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 boolean isLongitudeEditor() {
+ return longitudeEditor;
+ }
+
+ public void setLongitudeEditor(boolean longitudeEditor) {
+ Object oldValue = isLongitudeEditor();
+ this.longitudeEditor = longitudeEditor;
+ firePropertyChange(PROPERTY_BEAN, oldValue, longitudeEditor);
+ }
+
+ 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 getMaskFormatterPattern() {
+ String pattern = "**°**''**''''";
+ if (isLongitudeEditor()) {
+ // add one more degre
+ pattern = "*" + pattern;
+ }
+ return pattern;
+ }
+
+ public String getStringPattern() {
+ String pattern = "%s%s°%s'%s''";
+ return pattern;
+ }
+}
Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/gis/DmsCoordinateEditorModel.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
1
0
r2750 - in trunk: jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor jaxx-demo/src/main/java/jaxx/demo/tree jaxx-widgets/src/main/java/jaxx/runtime/swing/editor
by tchemit@users.nuiton.org 22 Nov '13
by tchemit@users.nuiton.org 22 Nov '13
22 Nov '13
Author: tchemit
Date: 2013-11-22 17:44:52 +0100 (Fri, 22 Nov 2013)
New Revision: 2750
Url: http://nuiton.org/projects/jaxx/repository/revisions/2750
Log:
fixes #2924: Introduce a new *Simple* time editor.
Added:
trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemo.css
trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemo.jaxx
trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoHandler.java
trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoModel.java
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditor.css
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditor.jaxx
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditorHandler.java
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditorModel.java
Modified:
trunk/jaxx-demo/src/main/java/jaxx/demo/tree/DemoDataProvider.java
Added: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemo.css
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemo.css (rev 0)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemo.css 2013-11-22 16:44:52 UTC (rev 2750)
@@ -0,0 +1,40 @@
+/*
+ * #%L
+ * JAXX :: Demo
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+#configPanel {
+ border:{new TitledBorder(_("jaxxdemo.numbereditor.configuration"))};
+ layout:{new GridLayout(0,1)};
+}
+
+#editor {
+ property:"time";
+ border:{new TitledBorder(_("jaxxdemo.timeeditor.editor"))};
+ bean:{demoModel};
+ date:{demoModel.getTime()};
+}
+
+#resultPane {
+ border:{new TitledBorder(_("jaxxdemo.timeeditor.model"))};
+ layout:{new BorderLayout()};
+}
Property changes on: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemo.css
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemo.jaxx
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemo.jaxx (rev 0)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemo.jaxx 2013-11-22 16:44:52 UTC (rev 2750)
@@ -0,0 +1,85 @@
+<jaxx.demo.DemoPanel layout='{new BorderLayout()}'>
+
+ <import>
+ jaxx.runtime.swing.editor.SimpleTimeEditor
+
+ static org.nuiton.i18n.I18n._
+ </import>
+
+ <!-- model -->
+ <SimpleTimeEditorDemoModel id='demoModel'/>
+
+ <script><![CDATA[
+
+@Override
+protected String[] getSources() {
+ return new String[]{ getDefaultSource(),
+ "SimpleTimeEditorModel.java",
+ "SimpleTimeEditorDemo.css"
+ };
+}
+
+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">
+
+ <!--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(_("jaxxdemo.timeeditor.editor"))}'/>
+ <!--property='time'-->
+ <!--bean='{demoModel}'-->
+ <!--date="{demoModel.getTime()}"/>-->
+ </cell>
+ </row>
+ <row>
+ <cell>
+
+ <JPanel id='resultPane'>
+
+ <JLabel constraints='BorderLayout.CENTER'
+ text='{_("jaxxdemo.timeeditor.value", demoModel.getTime())}'/>
+ </JPanel>
+
+ </cell>
+ </row>
+ </Table>
+
+
+</jaxx.demo.DemoPanel>
\ No newline at end of file
Property changes on: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemo.jaxx
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoHandler.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoHandler.java (rev 0)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoHandler.java 2013-11-22 16:44:52 UTC (rev 2750)
@@ -0,0 +1,10 @@
+package jaxx.demo.component.jaxx.editor;
+
+/**
+ * Created on 11/22/13.
+ *
+ * @author Tony CHEMIT <chemit(a)codelutin.com>
+ * @since 2.5.31
+ */
+public class SimpleTimeEditorDemoHandler {
+}
Property changes on: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoHandler.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoModel.java (from rev 2749, trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/TimeEditorDemoModel.java)
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoModel.java (rev 0)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/SimpleTimeEditorDemoModel.java 2013-11-22 16:44:52 UTC (rev 2750)
@@ -0,0 +1,57 @@
+/*
+ * #%L
+ * JAXX :: Demo
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package jaxx.demo.component.jaxx.editor;
+
+import 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 <chemit(a)codelutin.com>
+ * @since 2.5.31
+ */
+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);
+ }
+
+
+}
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/tree/DemoDataProvider.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/tree/DemoDataProvider.java 2013-11-12 09:12:54 UTC (rev 2749)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/tree/DemoDataProvider.java 2013-11-22 16:44:52 UTC (rev 2750)
@@ -28,13 +28,13 @@
import jaxx.demo.component.jaxx.BoxedDecoratorDemo;
import jaxx.demo.component.jaxx.StatusMessagePanelDemo;
import jaxx.demo.component.jaxx.editor.BeanComboBoxDemo;
-import jaxx.demo.component.jaxx.editor.BeanComboBoxDemoHandler;
import jaxx.demo.component.jaxx.editor.ComboEditorDemo;
import jaxx.demo.component.jaxx.editor.DatePickerDemo;
import jaxx.demo.component.jaxx.editor.FileEditorDemo;
import jaxx.demo.component.jaxx.editor.I18nEditorDemo;
import jaxx.demo.component.jaxx.editor.ListSelectorDemo;
import jaxx.demo.component.jaxx.editor.NumberEditorDemo;
+import jaxx.demo.component.jaxx.editor.SimpleTimeEditorDemo;
import jaxx.demo.component.jaxx.editor.TimeEditorDemo;
import jaxx.demo.component.swing.HidorButtonDemo;
import jaxx.demo.component.swing.JButtonDemo;
@@ -158,6 +158,7 @@
addMapping(n_("jaxxdemo.component.jaxx.editor"),
TimeEditorDemo.class,
+ SimpleTimeEditorDemo.class,
NumberEditorDemo.class,
ComboEditorDemo.class,
I18nEditorDemo.class,
Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditor.css
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditor.css (rev 0)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditor.css 2013-11-22 16:44:52 UTC (rev 2750)
@@ -0,0 +1,44 @@
+/*
+ * #%L
+ * JAXX :: Widgets
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+#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};
+}
Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditor.css
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditor.jaxx
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditor.jaxx (rev 0)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditor.jaxx 2013-11-22 16:44:52 UTC (rev 2750)
@@ -0,0 +1,63 @@
+<!--
+ #%L
+ JAXX :: Widgets
+ $Id$
+ $HeadURL$
+ %%
+ Copyright (C) 2008 - 2013 CodeLutin
+ %%
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Lesser Public License for more details.
+
+ You should have received a copy of the GNU General Lesser Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ #L%
+ -->
+
+<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>
\ No newline at end of file
Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditor.jaxx
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditorHandler.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditorHandler.java (rev 0)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditorHandler.java 2013-11-22 16:44:52 UTC (rev 2750)
@@ -0,0 +1,266 @@
+package jaxx.runtime.swing.editor;
+
+/*
+ * #%L
+ * JAXX :: Widgets
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+import jaxx.runtime.swing.editor.bean.BeanUIUtil;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.swing.JSpinner;
+import javax.swing.SpinnerDateModel;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.lang.reflect.Method;
+import java.util.Calendar;
+import java.util.Date;
+
+/**
+ * @author Tony CHEMIT <chemit(a)codelutin.com>
+ * @since 2.5.31
+ */
+public class SimpleTimeEditorHandler {
+
+ /** Logger. */
+ private static final Log log =
+ LogFactory.getLog(SimpleTimeEditorHandler.class);
+
+ 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 calendarDate;
+
+ protected final Calendar calendarMinute;
+
+ protected final Calendar calendarHour;
+
+ public SimpleTimeEditorHandler(SimpleTimeEditor editor) {
+ this.editor = editor;
+ this.model = editor.getModel();
+ this.calendarMinute = Calendar.getInstance();
+ this.calendarHour = Calendar.getInstance();
+ this.calendarDate = Calendar.getInstance();
+ }
+
+ 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"));
+
+
+// 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, new PropertyChangeListener() {
+
+ @Override
+ public void propertyChange(PropertyChangeEvent 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);
+ }
+
+ }
+ });
+
+ // When time model change, let's push it back in bean
+ model.addPropertyChangeListener(SimpleTimeEditorModel.PROPERTY_TIME_MODEL, new PropertyChangeListener() {
+
+ @Override
+ public void propertyChange(PropertyChangeEvent 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 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
+ int minute = newMinute;
+
+ 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 + ":" + minute);
+ }
+ model.setTimeModel(hour * 60 + minute);
+ }
+
+ 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 = BeanUIUtil.getMutator(bean, property);
+ }
+ return mutator;
+ }
+}
Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditorHandler.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditorModel.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditorModel.java (rev 0)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditorModel.java 2013-11-22 16:44:52 UTC (rev 2750)
@@ -0,0 +1,111 @@
+package jaxx.runtime.swing.editor;
+
+/*
+ * #%L
+ * JAXX :: Widgets
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2013 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+import org.jdesktop.beans.AbstractSerializableBean;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @author Tony CHEMIT <chemit(a)codelutin.com>
+ * @since 2.5.31
+ */
+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;
+ }
+
+}
Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/SimpleTimeEditorModel.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
1
0
The JAXX team is pleased to announce the jaxx-2.5.30 release!
JAXX Project
Documentation of the project can be found here:
http://maven-site.nuiton.org/jaxx
Changes
-------
Changes in this version include:
New features:
o Add a reset button on FileEditor Issue: 2909. Thanks to Tony Chemit. Resolved by tchemit.
Changes:
o Updates mavenpom to 4.3 Issue: 2907. Thanks to Tony Chemit. Resolved by tchemit.
o improve jws launching Issue: 2908. Thanks to Tony Chemit. Resolved by tchemit.
Downloads
---------
No release file deployed. (all files are deployed in the maven repository)
Maven artifacts
---------------
Artifacts are deployed in Maven Central Repository
http://repo1.maven.org/maven2/
Find us at
* http://search.maven.org/#artifactdetails|org.nuiton|jaxx|2.5.30|jar
Have fun!
-JAXX team
1
0
r2749 - in trunk: . jaxx-compiler jaxx-config jaxx-demo jaxx-maven-plugin jaxx-runtime jaxx-validator jaxx-widgets
by tchemit@users.nuiton.org 12 Nov '13
by tchemit@users.nuiton.org 12 Nov '13
12 Nov '13
Author: tchemit
Date: 2013-11-12 10:12:54 +0100 (Tue, 12 Nov 2013)
New Revision: 2749
Url: http://nuiton.org/projects/jaxx/repository/revisions/2749
Log:
[maven-release-plugin] prepare for next development iteration
Modified:
trunk/jaxx-compiler/pom.xml
trunk/jaxx-config/pom.xml
trunk/jaxx-demo/pom.xml
trunk/jaxx-maven-plugin/pom.xml
trunk/jaxx-runtime/pom.xml
trunk/jaxx-validator/pom.xml
trunk/jaxx-widgets/pom.xml
trunk/pom.xml
Modified: trunk/jaxx-compiler/pom.xml
===================================================================
--- trunk/jaxx-compiler/pom.xml 2013-11-12 09:12:49 UTC (rev 2748)
+++ trunk/jaxx-compiler/pom.xml 2013-11-12 09:12:54 UTC (rev 2749)
@@ -30,7 +30,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>jaxx</artifactId>
- <version>2.5.30</version>
+ <version>2.5.31-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.jaxx</groupId>
Modified: trunk/jaxx-config/pom.xml
===================================================================
--- trunk/jaxx-config/pom.xml 2013-11-12 09:12:49 UTC (rev 2748)
+++ trunk/jaxx-config/pom.xml 2013-11-12 09:12:54 UTC (rev 2749)
@@ -31,7 +31,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>jaxx</artifactId>
- <version>2.5.30</version>
+ <version>2.5.31-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.jaxx</groupId>
Modified: trunk/jaxx-demo/pom.xml
===================================================================
--- trunk/jaxx-demo/pom.xml 2013-11-12 09:12:49 UTC (rev 2748)
+++ trunk/jaxx-demo/pom.xml 2013-11-12 09:12:54 UTC (rev 2749)
@@ -30,7 +30,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>jaxx</artifactId>
- <version>2.5.30</version>
+ <version>2.5.31-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.jaxx</groupId>
Modified: trunk/jaxx-maven-plugin/pom.xml
===================================================================
--- trunk/jaxx-maven-plugin/pom.xml 2013-11-12 09:12:49 UTC (rev 2748)
+++ trunk/jaxx-maven-plugin/pom.xml 2013-11-12 09:12:54 UTC (rev 2749)
@@ -31,7 +31,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>jaxx</artifactId>
- <version>2.5.30</version>
+ <version>2.5.31-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.jaxx</groupId>
Modified: trunk/jaxx-runtime/pom.xml
===================================================================
--- trunk/jaxx-runtime/pom.xml 2013-11-12 09:12:49 UTC (rev 2748)
+++ trunk/jaxx-runtime/pom.xml 2013-11-12 09:12:54 UTC (rev 2749)
@@ -30,7 +30,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>jaxx</artifactId>
- <version>2.5.30</version>
+ <version>2.5.31-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.jaxx</groupId>
Modified: trunk/jaxx-validator/pom.xml
===================================================================
--- trunk/jaxx-validator/pom.xml 2013-11-12 09:12:49 UTC (rev 2748)
+++ trunk/jaxx-validator/pom.xml 2013-11-12 09:12:54 UTC (rev 2749)
@@ -30,7 +30,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>jaxx</artifactId>
- <version>2.5.30</version>
+ <version>2.5.31-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.jaxx</groupId>
Modified: trunk/jaxx-widgets/pom.xml
===================================================================
--- trunk/jaxx-widgets/pom.xml 2013-11-12 09:12:49 UTC (rev 2748)
+++ trunk/jaxx-widgets/pom.xml 2013-11-12 09:12:54 UTC (rev 2749)
@@ -31,7 +31,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>jaxx</artifactId>
- <version>2.5.30</version>
+ <version>2.5.31-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.jaxx</groupId>
@@ -49,11 +49,11 @@
<!-- Source control management. -->
<scm>
- <connection>scm:svn:http://svn.nuiton.org/svn/jaxx/tags/jaxx-2.5.30/jaxx-widgets</connection>
+ <connection>scm:svn:http://svn.nuiton.org/svn/jaxx/trunk/jaxx-widgets</connection>
<developerConnection>
- scm:svn:http://svn.nuiton.org/svn/jaxx/tags/jaxx-2.5.30/jaxx-widgets
+ scm:svn:http://svn.nuiton.org/svn/jaxx/trunk/jaxx-widgets
</developerConnection>
- <url>http://nuiton.org/projects/jaxx/repository/show/trunkjaxx-widgets/tags/jaxx…</url>
+ <url>http://nuiton.org/projects/jaxx/repository/show/trunkjaxx-widgets</url>
</scm>
<dependencies>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2013-11-12 09:12:49 UTC (rev 2748)
+++ trunk/pom.xml 2013-11-12 09:12:54 UTC (rev 2749)
@@ -34,7 +34,7 @@
</parent>
<artifactId>jaxx</artifactId>
- <version>2.5.30</version>
+ <version>2.5.31-SNAPSHOT</version>
<modules>
<module>jaxx-runtime</module>
@@ -139,11 +139,11 @@
<!-- Source control management. -->
<scm>
- <connection>scm:svn:http://svn.nuiton.org/svn/jaxx/tags/jaxx-2.5.30</connection>
+ <connection>scm:svn:http://svn.nuiton.org/svn/jaxx/trunk</connection>
<developerConnection>
- scm:svn:http://svn.nuiton.org/svn/jaxx/tags/jaxx-2.5.30
+ scm:svn:http://svn.nuiton.org/svn/jaxx/trunk
</developerConnection>
- <url>http://nuiton.org/projects/jaxx/repository/show/tags/jaxx-2.5.30</url>
+ <url>http://nuiton.org/projects/jaxx/repository/show/trunk</url>
</scm>
<distributionManagement>
1
0
Author: tchemit
Date: 2013-11-12 10:12:49 +0100 (Tue, 12 Nov 2013)
New Revision: 2748
Url: http://nuiton.org/projects/jaxx/repository/revisions/2748
Log:
[maven-release-plugin] copy for tag jaxx-2.5.30
Added:
tags/jaxx-2.5.30/
1
0
r2747 - in trunk: . jaxx-compiler jaxx-config jaxx-demo jaxx-maven-plugin jaxx-runtime jaxx-validator jaxx-widgets
by tchemit@users.nuiton.org 12 Nov '13
by tchemit@users.nuiton.org 12 Nov '13
12 Nov '13
Author: tchemit
Date: 2013-11-12 10:12:46 +0100 (Tue, 12 Nov 2013)
New Revision: 2747
Url: http://nuiton.org/projects/jaxx/repository/revisions/2747
Log:
[maven-release-plugin] prepare release jaxx-2.5.30
Modified:
trunk/jaxx-compiler/pom.xml
trunk/jaxx-config/pom.xml
trunk/jaxx-demo/pom.xml
trunk/jaxx-maven-plugin/pom.xml
trunk/jaxx-runtime/pom.xml
trunk/jaxx-validator/pom.xml
trunk/jaxx-widgets/pom.xml
trunk/pom.xml
Modified: trunk/jaxx-compiler/pom.xml
===================================================================
--- trunk/jaxx-compiler/pom.xml 2013-11-12 09:03:44 UTC (rev 2746)
+++ trunk/jaxx-compiler/pom.xml 2013-11-12 09:12:46 UTC (rev 2747)
@@ -30,7 +30,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>jaxx</artifactId>
- <version>2.5.30-SNAPSHOT</version>
+ <version>2.5.30</version>
</parent>
<groupId>org.nuiton.jaxx</groupId>
Modified: trunk/jaxx-config/pom.xml
===================================================================
--- trunk/jaxx-config/pom.xml 2013-11-12 09:03:44 UTC (rev 2746)
+++ trunk/jaxx-config/pom.xml 2013-11-12 09:12:46 UTC (rev 2747)
@@ -31,7 +31,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>jaxx</artifactId>
- <version>2.5.30-SNAPSHOT</version>
+ <version>2.5.30</version>
</parent>
<groupId>org.nuiton.jaxx</groupId>
Modified: trunk/jaxx-demo/pom.xml
===================================================================
--- trunk/jaxx-demo/pom.xml 2013-11-12 09:03:44 UTC (rev 2746)
+++ trunk/jaxx-demo/pom.xml 2013-11-12 09:12:46 UTC (rev 2747)
@@ -30,7 +30,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>jaxx</artifactId>
- <version>2.5.30-SNAPSHOT</version>
+ <version>2.5.30</version>
</parent>
<groupId>org.nuiton.jaxx</groupId>
Modified: trunk/jaxx-maven-plugin/pom.xml
===================================================================
--- trunk/jaxx-maven-plugin/pom.xml 2013-11-12 09:03:44 UTC (rev 2746)
+++ trunk/jaxx-maven-plugin/pom.xml 2013-11-12 09:12:46 UTC (rev 2747)
@@ -31,7 +31,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>jaxx</artifactId>
- <version>2.5.30-SNAPSHOT</version>
+ <version>2.5.30</version>
</parent>
<groupId>org.nuiton.jaxx</groupId>
Modified: trunk/jaxx-runtime/pom.xml
===================================================================
--- trunk/jaxx-runtime/pom.xml 2013-11-12 09:03:44 UTC (rev 2746)
+++ trunk/jaxx-runtime/pom.xml 2013-11-12 09:12:46 UTC (rev 2747)
@@ -30,7 +30,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>jaxx</artifactId>
- <version>2.5.30-SNAPSHOT</version>
+ <version>2.5.30</version>
</parent>
<groupId>org.nuiton.jaxx</groupId>
Modified: trunk/jaxx-validator/pom.xml
===================================================================
--- trunk/jaxx-validator/pom.xml 2013-11-12 09:03:44 UTC (rev 2746)
+++ trunk/jaxx-validator/pom.xml 2013-11-12 09:12:46 UTC (rev 2747)
@@ -30,7 +30,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>jaxx</artifactId>
- <version>2.5.30-SNAPSHOT</version>
+ <version>2.5.30</version>
</parent>
<groupId>org.nuiton.jaxx</groupId>
Modified: trunk/jaxx-widgets/pom.xml
===================================================================
--- trunk/jaxx-widgets/pom.xml 2013-11-12 09:03:44 UTC (rev 2746)
+++ trunk/jaxx-widgets/pom.xml 2013-11-12 09:12:46 UTC (rev 2747)
@@ -31,7 +31,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>jaxx</artifactId>
- <version>2.5.30-SNAPSHOT</version>
+ <version>2.5.30</version>
</parent>
<groupId>org.nuiton.jaxx</groupId>
@@ -49,11 +49,11 @@
<!-- Source control management. -->
<scm>
- <connection>scm:svn:http://svn.nuiton.org/svn/jaxx/trunk/jaxx-widgets</connection>
+ <connection>scm:svn:http://svn.nuiton.org/svn/jaxx/tags/jaxx-2.5.30/jaxx-widgets</connection>
<developerConnection>
- scm:svn:http://svn.nuiton.org/svn/jaxx/trunk/jaxx-widgets
+ scm:svn:http://svn.nuiton.org/svn/jaxx/tags/jaxx-2.5.30/jaxx-widgets
</developerConnection>
- <url>http://nuiton.org/projects/jaxx/repository/show/trunkjaxx-widgets</url>
+ <url>http://nuiton.org/projects/jaxx/repository/show/trunkjaxx-widgets/tags/jaxx…</url>
</scm>
<dependencies>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2013-11-12 09:03:44 UTC (rev 2746)
+++ trunk/pom.xml 2013-11-12 09:12:46 UTC (rev 2747)
@@ -23,9 +23,7 @@
<http://www.gnu.org/licenses/lgpl-3.0.html>.
#L%
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -36,7 +34,7 @@
</parent>
<artifactId>jaxx</artifactId>
- <version>2.5.30-SNAPSHOT</version>
+ <version>2.5.30</version>
<modules>
<module>jaxx-runtime</module>
@@ -141,11 +139,11 @@
<!-- Source control management. -->
<scm>
- <connection>scm:svn:http://svn.nuiton.org/svn/jaxx/trunk</connection>
+ <connection>scm:svn:http://svn.nuiton.org/svn/jaxx/tags/jaxx-2.5.30</connection>
<developerConnection>
- scm:svn:http://svn.nuiton.org/svn/jaxx/trunk
+ scm:svn:http://svn.nuiton.org/svn/jaxx/tags/jaxx-2.5.30
</developerConnection>
- <url>http://nuiton.org/projects/jaxx/repository/show/trunk</url>
+ <url>http://nuiton.org/projects/jaxx/repository/show/tags/jaxx-2.5.30</url>
</scm>
<distributionManagement>
1
0