Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

merge some fixes from 2.0.x

git-svn-id: https://svn.apache.org/repos/asf/pivot/trunk@1446824 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
commit feb0b8b51c9db0ea461b7014bd690ff6e75b025b 1 parent d2b2427
Sandro Martini authored
Showing with 955 additions and 47 deletions.
  1. +1 −1  build.xml
  2. +0 −1  examples/.classpath
  3. +17 −18 examples/.project
  4. +9 −0 examples/src/org/apache/pivot/examples/scripting/README.txt
  5. +118 −0 tests/src/org/apache/pivot/tests/LabelAntialiasTest.java
  6. +83 −5 tests/src/org/apache/pivot/tests/TextInputValidatorTest.java
  7. +36 −0 tests/src/org/apache/pivot/tests/issues/pivot_888.bxml
  8. +121 −0 tests/src/org/apache/pivot/tests/table_pane_test2.bxml
  9. +103 −0 tests/src/org/apache/pivot/tests/table_view_test4.bxml
  10. +97 −0 tests/src/org/apache/pivot/tests/table_view_test_empty.bxml
  11. +26 −1 tests/src/org/apache/pivot/tests/text_input_validator_test.bxml
  12. +4 −1 wtk/src/org/apache/pivot/wtk/ListView.java
  13. +4 −1 wtk/src/org/apache/pivot/wtk/TableView.java
  14. +13 −3 wtk/src/org/apache/pivot/wtk/TextArea.java
  15. +1 −1  wtk/src/org/apache/pivot/wtk/TextInput.java
  16. +3 −2 wtk/src/org/apache/pivot/wtk/content/ButtonData.java
  17. +4 −0 wtk/src/org/apache/pivot/wtk/media/Image.java
  18. +32 −0 wtk/src/org/apache/pivot/wtk/validation/BigDecimalValidator.java
  19. +32 −0 wtk/src/org/apache/pivot/wtk/validation/BigIntegerValidator.java
  20. +91 −0 wtk/src/org/apache/pivot/wtk/validation/ComparableRangeValidator.java
  21. +56 −0 wtk/src/org/apache/pivot/wtk/validation/ComparableValidator.java
  22. +34 −1 wtk/src/org/apache/pivot/wtk/validation/DecimalValidator.java
  23. +4 −0 wtk/src/org/apache/pivot/wtk/validation/DoubleRangeValidator.java
  24. +4 −2 wtk/src/org/apache/pivot/wtk/validation/DoubleValidator.java
  25. +31 −0 wtk/src/org/apache/pivot/wtk/validation/EmptyTextValidator.java
  26. +4 −0 wtk/src/org/apache/pivot/wtk/validation/FloatRangeValidator.java
  27. +7 −6 wtk/src/org/apache/pivot/wtk/validation/FloatValidator.java
  28. +12 −4 wtk/src/org/apache/pivot/wtk/validation/FormattedValidator.java
  29. +4 −0 wtk/src/org/apache/pivot/wtk/validation/IntRangeValidator.java
  30. +4 −0 wtk/src/org/apache/pivot/wtk/validation/IntValidator.java
View
2  build.xml
@@ -308,7 +308,7 @@ limitations under the License.
<javadoc packagenames="@{package}"
destdir="${folder.doc}/@{jarFile}"
author="true" version="true" use="true"
- package="true"
+ package="true"
classpath="${java.class.path}">
<classpath>
<path refid="classpath.general"/>
View
1  examples/.classpath
@@ -2,7 +2,6 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
- <classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/core"/>
<classpathentry combineaccessrules="false" kind="src" path="/web"/>
View
35 examples/.project
@@ -1,18 +1,17 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>examples</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.scala-ide.sdt.core.scalabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.scala-ide.sdt.core.scalanature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>examples</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
View
9 examples/src/org/apache/pivot/examples/scripting/README.txt
@@ -0,0 +1,9 @@
+//
+// README for org.apache.pivot.examples.scripting Samples
+//
+
+In this package there are some Groovy sources and even some Scala sources, but in our ant builds they are not compiled.
+To run those examples from an IDE (like Eclipse), you must enable support for those languages for the project containing them (examples).
+
+Note that in case of problems, for example a configured Nature for that project but the related Plugin is not installed,
+it will not be possible to run even Java examples because nothing in that project will be compiled.
View
118 tests/src/org/apache/pivot/tests/LabelAntialiasTest.java
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.tests;
+
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.GraphicsEnvironment;
+import java.awt.Toolkit;
+import java.awt.geom.AffineTransform;
+
+import org.apache.pivot.collections.Map;
+import org.apache.pivot.wtk.Application;
+import org.apache.pivot.wtk.DesktopApplicationContext;
+import org.apache.pivot.wtk.Display;
+import org.apache.pivot.wtk.HorizontalAlignment;
+import org.apache.pivot.wtk.Label;
+import org.apache.pivot.wtk.VerticalAlignment;
+import org.apache.pivot.wtk.Window;
+
+public class LabelAntialiasTest extends Application.Adapter {
+ private Window window = null;
+
+ private Label buildLabel(double rotation) {
+ Label label = new Label();
+
+ Font font = new Font("Arial", Font.BOLD, 64);
+
+ AffineTransform fontAT = new AffineTransform();
+ // Derive a new font using a rotation transform
+ fontAT.rotate(rotation * java.lang.Math.PI / 180.0d);
+ Font fontDerived = font.deriveFont(fontAT);
+
+ label.setText("Hello at " + rotation + " degree.");
+ label.getStyles().put("color", Color.RED);
+ label.getStyles().put("font", fontDerived);
+ label.getStyles().put("horizontalAlignment", HorizontalAlignment.CENTER);
+ label.getStyles().put("verticalAlignment", VerticalAlignment.TOP);
+
+ return label;
+ }
+
+ /**
+ * Write to console some details of Desktop Hints, for Font Rendering.
+ *
+ * @see org.apache.pivot.wtk.Platform#initializeFontRenderContext
+ */
+ private void showFontDesktopHints() {
+ System.out.println("Show Font Desktop Hints:");
+
+ Toolkit toolkit = Toolkit.getDefaultToolkit();
+ java.util.Map<?, ?> fontDesktopHints =
+ (java.util.Map<?, ?>)toolkit.getDesktopProperty("awt.font.desktophints");
+
+ System.out.println(fontDesktopHints);
+ }
+
+ /**
+ * Write to console the list of Font families found in the System.
+ */
+ private void showFontFamilies() {
+ System.out.println("Show Font Families:");
+
+ GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
+ String []fontFamilies = ge.getAvailableFontFamilyNames();
+ int fontFamiliesNumber = fontFamilies.length;
+ StringBuffer fontFamilyNames = new StringBuffer(1024);
+ for (int i=0; i < fontFamiliesNumber; i++) {
+ if (i > 0) {
+ fontFamilyNames.append(", ");
+ }
+ fontFamilyNames.append(fontFamilies[i]);
+ }
+ System.out.println(fontFamilyNames);
+ }
+
+ @Override
+ public void startup(Display display, Map<String, String> properties) {
+ window = new Window();
+
+ showFontDesktopHints();
+ showFontFamilies();
+
+ Label label = buildLabel(45);
+ window.setContent(label);
+
+ window.setTitle("Label Antialiasing Test");
+ window.setMaximized(true);
+ window.open(display);
+ }
+
+ @Override
+ public boolean shutdown(boolean optional) {
+ if (window != null) {
+ window.close();
+ }
+
+ return false;
+ }
+
+ public static void main(String[] args) {
+ DesktopApplicationContext.main(LabelAntialiasTest.class, args);
+ }
+
+}
View
88 tests/src/org/apache/pivot/tests/TextInputValidatorTest.java
@@ -13,6 +13,11 @@
*/
package org.apache.pivot.tests;
+// import java.text.DecimalFormat;
+import java.math.BigDecimal;
+import java.text.NumberFormat;
+import java.util.Locale;
+
import org.apache.pivot.beans.BXMLSerializer;
import org.apache.pivot.collections.Map;
import org.apache.pivot.wtk.Application;
@@ -23,19 +28,29 @@
import org.apache.pivot.wtk.TextInput;
import org.apache.pivot.wtk.TextInputListener;
import org.apache.pivot.wtk.Window;
+import org.apache.pivot.wtk.validation.BigDecimalValidator;
+import org.apache.pivot.wtk.validation.ComparableRangeValidator;
import org.apache.pivot.wtk.validation.DoubleValidator;
-import org.apache.pivot.wtk.validation.FloatValidator;
+import org.apache.pivot.wtk.validation.EmptyTextValidator;
import org.apache.pivot.wtk.validation.FloatRangeValidator;
+import org.apache.pivot.wtk.validation.FloatValidator;
import org.apache.pivot.wtk.validation.IntRangeValidator;
import org.apache.pivot.wtk.validation.NotEmptyTextValidator;
import org.apache.pivot.wtk.validation.RegexTextValidator;
import org.apache.pivot.wtk.validation.Validator;
+// import java.util.Formatter;
/**
* Text input validator test.
*/
public class TextInputValidatorTest extends Application.Adapter {
+ private Locale locale = Locale.getDefault(); // the default locale
+
private Window window = null;
+ private TextInput textinputLocale = null;
+ private TextInput textinputComparableBigDecimal = null;
+ private TextInput textinputComparableRange = null;
+ private Label invalidComparableRangeLabel = null;
private TextInput textinputDouble = null;
private TextInput textinputFloat = null;
private TextInput textinputFloatRange = null;
@@ -44,13 +59,32 @@
private TextInput textinputDateRegex = null;
private TextInput textinputCustomBoolean = null;
private TextInput textinputNotEmptyText = null;
+ private TextInput textinputEmptyText = null;
@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
+ System.out.println("Starting TextInputValidatorTest ...");
+ System.out.println("current Locale is " + locale);
+
+ // sample different ways to format numbers in i18n compatible way
+ NumberFormat nf = NumberFormat.getInstance();
+ //
+ // String customDecimalPattern = ""###,###.###"";
+ // DecimalFormat df = new DecimalFormat(customDecimalPattern);
+ //
+ // StringBuffer sb = new StringBuffer();
+ // Formatter formatter = new Formatter(sb, locale);
+ // String customDecimalFormat = "%,.3f";
+ //
+
BXMLSerializer bxmlSerializer = new BXMLSerializer();
window = new Window((Component)bxmlSerializer.readObject(
getClass().getResource("text_input_validator_test.bxml")));
+ textinputLocale = (TextInput)bxmlSerializer.getNamespace().get("textinputLocale");
+
+ textinputComparableBigDecimal = (TextInput)bxmlSerializer.getNamespace().get("textinputComparableBigDecimal");
+ textinputComparableRange = (TextInput)bxmlSerializer.getNamespace().get("textinputComparableRange");
textinputDouble = (TextInput)bxmlSerializer.getNamespace().get("textinputDouble");
textinputFloat = (TextInput)bxmlSerializer.getNamespace().get("textinputFloat");
textinputFloatRange = (TextInput)bxmlSerializer.getNamespace().get("textinputFloatRange");
@@ -58,16 +92,56 @@ public void startup(Display display, Map<String, String> properties) throws Exce
textinputDateRegex = (TextInput)bxmlSerializer.getNamespace().get("textinputDateRegex");
textinputCustomBoolean = (TextInput)bxmlSerializer.getNamespace().get("textinputCustomBoolean");
textinputNotEmptyText = (TextInput)bxmlSerializer.getNamespace().get("textinputNotEmptyText");
+ textinputEmptyText = (TextInput)bxmlSerializer.getNamespace().get("textinputEmptyText");
+
+ textinputLocale.setText(locale.toString());
+
+ String testValue = "123456789.0";
+ // new, validate a value but using BigDecimalValidator (subclass of ComparableValidator)
+ textinputComparableBigDecimal.setText("1e300"); // huge value, and outside double range ...
+ BigDecimalValidator bdComp = new BigDecimalValidator();
+ System.out.println("BigDecimalValidator: created instance with value: " + bdComp);
+ bdComp.setAutoTrim(true); // enable auto-trim of input string, before validating
+ System.out.println("BigDecimalValidator: enable auto-trim of input string, before validating");
+ textinputComparableBigDecimal.setValidator(bdComp);
+
+ // new, validate in a range but using ComparableRangeValidator
+ textinputComparableRange.setText(nf.format(new BigDecimal(testValue)));
+ ComparableRangeValidator<BigDecimal> bdCompRange = new ComparableRangeValidator<BigDecimal>(
+ new BigDecimal("2.0"), new BigDecimal("123456789")
+ );
+ System.out.println("ComparableRangeValidator: created instance with value: " + bdCompRange);
+ bdCompRange.setAutoTrim(true); // enable auto-trim of input string, before validating
+ System.out.println("ComparableRangeValidator: enable auto-trim of input string, before validating");
+ textinputComparableRange.setValidator(bdCompRange);
+ textinputComparableRange.getTextInputListeners().add(new TextInputListener.Adapter() {
+ @Override
+ public void textValidChanged(TextInput textInput) {
+ invalidComparableRangeLabel.setText(textInput.isTextValid() ? "valid" : "invalid");
+ }
+ });
+ invalidComparableRangeLabel = (Label)bxmlSerializer.getNamespace().get("invalidComparableRangeLabel");
- textinputDouble.setText("\u221E");
+ textinputDouble.setText("\u221E"); // infinite symbol
textinputDouble.setValidator(new DoubleValidator());
- textinputFloat.setText("1.5");
+ // textinputFloat.setText("123456.789");
+ // new, show different ways to format decimal values in i18n format
+ Double value = new Double(testValue);
+ // textinputFloat.setText(value.toString());
+ // textinputFloat.setText(String.format(customDecimalFormat, value)); // sample using String.format
+ // formatter.format(customDecimalFormat, value); // sample using Formatter
+ // textinputFloat.setText(sb.toString()); // sample using Formatter
+ // textinputFloat.setText(nf.format(value)); // sample using NumberFormat
+ // textinputFloat.setText(df.format(value)); // sample using DecimalFormat
+ textinputFloat.setText(nf.format(value)); // using this as a sample
textinputFloat.setValidator(new FloatValidator());
// standard float range model
- textinputFloatRange.setText("0.5");
- textinputFloatRange.setValidator(new FloatRangeValidator(0.3f, 2000f));
+ // note that float approximations could give errors,
+ // try to increment/decrement the initial value near a range end, to see problems ...
+ textinputFloatRange.setText(nf.format(new Float(testValue)));
+ textinputFloatRange.setValidator(new FloatRangeValidator(2.0f, 123456789f));
// test the listener by updating a label
textinputFloatRange.getTextInputListeners().add(new TextInputListener.Adapter() {
@@ -101,6 +175,10 @@ public boolean isValid(String s) {
textinputNotEmptyText.setText(" Not Empty, and with spaces ");
textinputNotEmptyText.setValidator(new NotEmptyTextValidator());
+ // validate any empty text, edge case
+ textinputEmptyText.setText(" ");
+ textinputEmptyText.setValidator(new EmptyTextValidator());
+
window.setTitle("Text Input Validator Test");
window.setMaximized(true);
View
36 tests/src/org/apache/pivot/tests/issues/pivot_888.bxml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License,
+Version 2.0 (the "License"); you may not use this file except in
+compliance with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+
+<Window title="Pivot-880" maximized="true"
+ bxml:id="window"
+ xmlns:bxml="http://pivot.apache.org/bxml"
+ xmlns="org.apache.pivot.wtk"
+>
+
+<Form>
+ <Form.Section>
+ <TextInput bxml:id="textInput" text="${textArea.text}"/>
+ <Border>
+ <FillPane minimumWidth="300" minimumHeight="100">
+ <TextArea bxml:id="textArea" text="${textInput.text}"/>
+ </FillPane>
+ </Border>
+ </Form.Section>
+</Form>
+
+</Window>
View
121 tests/src/org/apache/pivot/tests/table_pane_test2.bxml
@@ -0,0 +1,121 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License,
+Version 2.0 (the "License"); you may not use this file except in
+compliance with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+
+<Window bxml:id="window"
+ title="TablePane Test2, with variable row height" maximized="true"
+ xmlns:bxml="http://pivot.apache.org/bxml"
+ xmlns:collections="org.apache.pivot.collections"
+ xmlns:content="org.apache.pivot.wtk.content"
+ xmlns="org.apache.pivot.wtk"
+>
+ <bxml:script>
+ <![CDATA[
+ importPackage(java.net);
+ importPackage(org.apache.pivot.util);
+ importPackage(org.apache.pivot.wtk);
+ importPackage(org.apache.pivot.wtk.media);
+
+ var s = "ABCDE ABCDE ABCDE ABCDE";
+ var s2 = "First Line.\nSecond Line.";
+ var b = true;
+ var n = 100.25;
+ var d = new CalendarDate();
+ var location = new java.io.File("bin/" // add this to run from inside eclipse ...
+ + "org/apache/pivot/tests" // current package, view as folders
+ // + "/go-home.png" // image name
+ ).toURI().toURL();
+ java.lang.System.out.println("location for the image to load = \"" + location + "\"");
+ var i = Image.load(new URL(location, "go-home.png"));
+ java.lang.System.out.println("image = " + i);
+ ]]>
+ </bxml:script>
+
+ <TablePane
+ styles="{padding:6, verticalSpacing:8}"
+ >
+ <columns>
+ <TablePane.Column width="1*" />
+ </columns>
+
+ <TablePane.Row height="-1">
+ <PushButton buttonData="Start"/>
+ </TablePane.Row>
+ <TablePane.Row height="-1">
+
+ <TableView>
+ <columns>
+ <TableView.Column name="value" width="-1">
+ <cellRenderer>
+ <content:TableViewMultiCellRenderer>
+ <bxml:define>
+<!-- // multiline
+ <content:TableViewTextAreaCellRenderer bxml:id="multilineCellRenderer"/>
+//-->
+<!-- // no multiline
+ <content:TableViewMultiCellRenderer bxml:id="multilineCellRenderer"/>
+//-->
+ <content:TableViewTextAreaCellRenderer bxml:id="multilineCellRenderer"/>
+
+ <content:TableViewBooleanCellRenderer bxml:id="booleanCellRenderer"/>
+ <content:TableViewNumberCellRenderer bxml:id="numberCellRenderer"/>
+ <content:TableViewDateCellRenderer bxml:id="dateCellRenderer"/>
+ <content:TableViewImageCellRenderer bxml:id="imageCellRenderer" preferredHeight="40"/>
+ </bxml:define>
+
+ <rendererMappings>
+<!-- // no multiline
+ <content:TableViewMultiCellRenderer.RendererMapping valueClass="org.apache.pivot.wtk.TextArea"
+ cellRenderer="$multilineCellRenderer"/>
+//-->
+<!-- // multiline
+ <content:TableViewMultiCellRenderer.RendererMapping valueClass="java.lang.String"
+ cellRenderer="$multilineCellRenderer"/>
+//-->
+ <content:TableViewMultiCellRenderer.RendererMapping valueClass="java.lang.String"
+ cellRenderer="$multilineCellRenderer"/>
+
+ <content:TableViewMultiCellRenderer.RendererMapping valueClass="java.lang.Boolean"
+ cellRenderer="$booleanCellRenderer"/>
+ <content:TableViewMultiCellRenderer.RendererMapping valueClass="java.lang.Number"
+ cellRenderer="$numberCellRenderer"/>
+ <content:TableViewMultiCellRenderer.RendererMapping valueClass="org.apache.pivot.util.CalendarDate"
+ cellRenderer="$dateCellRenderer"/>
+ <content:TableViewMultiCellRenderer.RendererMapping valueClass="org.apache.pivot.wtk.media.Image"
+ cellRenderer="$imageCellRenderer"/>
+ </rendererMappings>
+ </content:TableViewMultiCellRenderer>
+ </cellRenderer>
+ </TableView.Column>
+
+ <TableView.Column width="1*"/>
+ </columns>
+
+ <collections:HashMap value="$s"/>
+ <collections:HashMap value="$s2"/>
+ <collections:HashMap value="$b"/>
+ <collections:HashMap value="$n"/>
+ <collections:HashMap value="$d"/>
+ <collections:HashMap value="$i"/>
+ </TableView>
+
+ </TablePane.Row>
+ <TablePane.Row height="-1">
+ <PushButton buttonData="End"/>
+ </TablePane.Row>
+ </TablePane>
+</Window>
View
103 tests/src/org/apache/pivot/tests/table_view_test4.bxml
@@ -0,0 +1,103 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License,
+Version 2.0 (the "License"); you may not use this file except in
+compliance with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+
+<Window bxml:id="window"
+ title="Table View Test4, with renderer for multi-line texts" maximized="true"
+ xmlns:bxml="http://pivot.apache.org/bxml"
+ xmlns:collections="org.apache.pivot.collections"
+ xmlns:content="org.apache.pivot.wtk.content"
+ xmlns="org.apache.pivot.wtk"
+>
+ <bxml:script>
+ <![CDATA[
+ importPackage(java.net);
+ importPackage(org.apache.pivot.util);
+ importPackage(org.apache.pivot.wtk);
+ importPackage(org.apache.pivot.wtk.media);
+
+ var s = "ABCDE ABCDE ABCDE ABCDE";
+ var s2 = "First Line.\nSecond Line.";
+ var b = true;
+ var n = 100.25;
+ var d = new CalendarDate();
+ var location = new java.io.File("bin/" // add this to run from inside eclipse ...
+ + "org/apache/pivot/tests" // current package, view as folders
+ // + "/go-home.png" // image name
+ ).toURI().toURL();
+ java.lang.System.out.println("location for the image to load = \"" + location + "\"");
+ var i = Image.load(new URL(location, "go-home.png"));
+ java.lang.System.out.println("image = " + i);
+ ]]>
+ </bxml:script>
+
+ <TableView>
+ <columns>
+ <TableView.Column name="value" width="-1">
+ <cellRenderer>
+ <content:TableViewMultiCellRenderer>
+ <bxml:define>
+<!-- // multiline
+ <content:TableViewTextAreaCellRenderer bxml:id="multilineCellRenderer"/>
+//-->
+<!-- // no multiline
+ <content:TableViewMultiCellRenderer bxml:id="multilineCellRenderer"/>
+//-->
+ <content:TableViewTextAreaCellRenderer bxml:id="multilineCellRenderer"/>
+
+ <content:TableViewBooleanCellRenderer bxml:id="booleanCellRenderer"/>
+ <content:TableViewNumberCellRenderer bxml:id="numberCellRenderer"/>
+ <content:TableViewDateCellRenderer bxml:id="dateCellRenderer"/>
+ <content:TableViewImageCellRenderer bxml:id="imageCellRenderer" preferredHeight="40"/>
+ </bxml:define>
+
+ <rendererMappings>
+<!-- // no multiline
+ <content:TableViewMultiCellRenderer.RendererMapping valueClass="org.apache.pivot.wtk.TextArea"
+ cellRenderer="$multilineCellRenderer"/>
+//-->
+<!-- // multiline
+ <content:TableViewMultiCellRenderer.RendererMapping valueClass="java.lang.String"
+ cellRenderer="$multilineCellRenderer"/>
+//-->
+ <content:TableViewMultiCellRenderer.RendererMapping valueClass="java.lang.String"
+ cellRenderer="$multilineCellRenderer"/>
+
+ <content:TableViewMultiCellRenderer.RendererMapping valueClass="java.lang.Boolean"
+ cellRenderer="$booleanCellRenderer"/>
+ <content:TableViewMultiCellRenderer.RendererMapping valueClass="java.lang.Number"
+ cellRenderer="$numberCellRenderer"/>
+ <content:TableViewMultiCellRenderer.RendererMapping valueClass="org.apache.pivot.util.CalendarDate"
+ cellRenderer="$dateCellRenderer"/>
+ <content:TableViewMultiCellRenderer.RendererMapping valueClass="org.apache.pivot.wtk.media.Image"
+ cellRenderer="$imageCellRenderer"/>
+ </rendererMappings>
+ </content:TableViewMultiCellRenderer>
+ </cellRenderer>
+ </TableView.Column>
+
+ <TableView.Column width="1*"/>
+ </columns>
+
+ <collections:HashMap value="$s"/>
+ <collections:HashMap value="$s2"/>
+ <collections:HashMap value="$b"/>
+ <collections:HashMap value="$n"/>
+ <collections:HashMap value="$d"/>
+ <collections:HashMap value="$i"/>
+ </TableView>
+</Window>
View
97 tests/src/org/apache/pivot/tests/table_view_test_empty.bxml
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License,
+Version 2.0 (the "License"); you may not use this file except in
+compliance with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+
+<Window bxml:id="window"
+ title="Table View Test, without data" maximized="true"
+ xmlns:bxml="http://pivot.apache.org/bxml"
+ xmlns:collections="org.apache.pivot.collections"
+ xmlns:content="org.apache.pivot.wtk.content"
+ xmlns="org.apache.pivot.wtk"
+>
+ <bxml:script>
+ <![CDATA[
+ importPackage(java.net);
+ importPackage(org.apache.pivot.util);
+ importPackage(org.apache.pivot.wtk);
+ importPackage(org.apache.pivot.wtk.media);
+
+ var s = "ABCDE ABCDE ABCDE ABCDE";
+ var s2 = "First Line.\nSecond Line.";
+ var b = true;
+ var n = 100.25;
+ var d = new CalendarDate();
+ var location = new java.io.File("bin/" // add this to run from inside eclipse ...
+ + "org/apache/pivot/tests" // current package, view as folders
+ // + "/go-home.png" // image name
+ ).toURI().toURL();
+ java.lang.System.out.println("location for the image to load = \"" + location + "\"");
+ var i = Image.load(new URL(location, "go-home.png"));
+ java.lang.System.out.println("image = " + i);
+ ]]>
+ </bxml:script>
+
+ <TableView>
+ <columns>
+ <TableView.Column name="value" width="-1">
+ <cellRenderer>
+ <content:TableViewMultiCellRenderer>
+ <bxml:define>
+<!-- // multiline
+ <content:TableViewTextAreaCellRenderer bxml:id="multilineCellRenderer"/>
+//-->
+<!-- // no multiline
+ <content:TableViewMultiCellRenderer bxml:id="multilineCellRenderer"/>
+//-->
+ <content:TableViewTextAreaCellRenderer bxml:id="multilineCellRenderer"/>
+
+ <content:TableViewBooleanCellRenderer bxml:id="booleanCellRenderer"/>
+ <content:TableViewNumberCellRenderer bxml:id="numberCellRenderer"/>
+ <content:TableViewDateCellRenderer bxml:id="dateCellRenderer"/>
+ <content:TableViewImageCellRenderer bxml:id="imageCellRenderer"/>
+ </bxml:define>
+
+ <rendererMappings>
+<!-- // no multiline
+ <content:TableViewMultiCellRenderer.RendererMapping valueClass="org.apache.pivot.wtk.TextArea"
+ cellRenderer="$multilineCellRenderer"/>
+//-->
+<!-- // multiline
+ <content:TableViewMultiCellRenderer.RendererMapping valueClass="java.lang.String"
+ cellRenderer="$multilineCellRenderer"/>
+//-->
+ <content:TableViewMultiCellRenderer.RendererMapping valueClass="java.lang.String"
+ cellRenderer="$multilineCellRenderer"/>
+
+ <content:TableViewMultiCellRenderer.RendererMapping valueClass="java.lang.Boolean"
+ cellRenderer="$booleanCellRenderer"/>
+ <content:TableViewMultiCellRenderer.RendererMapping valueClass="java.lang.Number"
+ cellRenderer="$numberCellRenderer"/>
+ <content:TableViewMultiCellRenderer.RendererMapping valueClass="org.apache.pivot.util.CalendarDate"
+ cellRenderer="$dateCellRenderer"/>
+ <content:TableViewMultiCellRenderer.RendererMapping valueClass="org.apache.pivot.wtk.media.Image"
+ cellRenderer="$imageCellRenderer"/>
+ </rendererMappings>
+ </content:TableViewMultiCellRenderer>
+ </cellRenderer>
+ </TableView.Column>
+
+ <TableView.Column width="1*"/>
+ </columns>
+
+ </TableView>
+</Window>
View
27 tests/src/org/apache/pivot/tests/text_input_validator_test.bxml
@@ -24,6 +24,24 @@ limitations under the License.
</columns>
<TablePane.Row height="-1">
+ <Label text="Current Locale:"/>
+ <TextInput bxml:id="textinputLocale" editable="false"/>
+ <Label text="use separators from the current Locale"/>
+ </TablePane.Row>
+ <TablePane.Row height="-1">
+ <Label text="BigDecimal value"/>
+ <TextInput bxml:id="textinputComparableBigDecimal"/>
+ <Label text="any BigDecimal value (huge and precise math, but no infinite)" />
+ </TablePane.Row>
+ <TablePane.Row height="-1">
+ <Label text="comparable range"/>
+ <TextInput bxml:id="textinputComparableRange"/>
+ <Label text="valid range: (same as float range, but using BigDecimal here)"
+ styles="{wrapText:true}"
+ />
+ <Label bxml:id="invalidComparableRangeLabel"/>
+ </TablePane.Row>
+ <TablePane.Row height="-1">
<Label text="double"/>
<TextInput bxml:id="textinputDouble"/>
<Label text="valid value: any double: ~4.94e-324 to ~1.79e+308 or &#x00B1;&#x221E;"/>
@@ -36,7 +54,7 @@ limitations under the License.
<TablePane.Row height="-1">
<Label text="float range"/>
<TextInput bxml:id="textinputFloatRange"/>
- <Label text="valid range: 0.3 .. 2000"/>
+ <Label text="valid range: 2.0 .. 123456789"/>
<Label bxml:id="invalidLabel"/>
</TablePane.Row>
<TablePane.Row height="-1">
@@ -61,4 +79,11 @@ limitations under the License.
styles="{wrapText:true}"
/>
</TablePane.Row>
+ <TablePane.Row height="-1">
+ <Label text="empty text"/>
+ <TextInput bxml:id="textinputEmptyText"/>
+ <Label text="valid values: any empty text (note that it will be trimmed)"
+ styles="{wrapText:true}"
+ />
+ </TablePane.Row>
</TablePane>
View
5 wtk/src/org/apache/pivot/wtk/ListView.java
@@ -783,7 +783,10 @@ public void setSelectedIndex(int index) {
if (index == -1) {
clearSelection();
} else {
- setSelectedRange(index, index);
+ int listDataLength = listData.getLength();
+ if (listDataLength > 0 && index < listDataLength) {
+ setSelectedRange(index, index);
+ }
}
}
View
5 wtk/src/org/apache/pivot/wtk/TableView.java
@@ -1413,7 +1413,10 @@ public void setSelectedIndex(int index) {
if (index == -1) {
clearSelection();
} else {
- setSelectedRange(index, index);
+ int tableDataLength = tableData.getLength();
+ if (tableDataLength > 0 && index < tableDataLength) {
+ setSelectedRange(index, index);
+ }
}
}
View
16 wtk/src/org/apache/pivot/wtk/TextArea.java
@@ -582,7 +582,7 @@ public void textBindMappingChanged(TextArea textArea, TextBindMapping previousTe
private boolean expandTabs = false;
- private int maximumLength = Integer.MAX_VALUE;
+ private int maximumLength = 1048575;
private boolean editable = true;
private String textKey = null;
@@ -601,7 +601,11 @@ public void textBindMappingChanged(TextArea textArea, TextBindMapping previousTe
public TextArea() {
installSkin(TextArea.class);
- setText("");
+ try {
+ setText(new StringReader(""));
+ } catch (IOException exception) {
+ throw new RuntimeException(exception);
+ }
}
@Override
@@ -684,8 +688,14 @@ public void setText(String text) {
throw new IllegalArgumentException();
}
+ if (text.length() > maximumLength) {
+ throw new IllegalArgumentException("Text length is greater than maximum length.");
+ }
+
try {
- setText(new StringReader(text));
+ if (!text.equals(this.getText())) {
+ setText(new StringReader(text));
+ }
} catch (IOException exception) {
throw new RuntimeException(exception);
}
View
2  wtk/src/org/apache/pivot/wtk/TextInput.java
@@ -265,7 +265,7 @@ public void textBindMappingChanged(TextInput textInput, TextBindMapping previous
private int selectionLength = 0;
private int textSize = DEFAULT_TEXT_SIZE;
- private int maximumLength = Integer.MAX_VALUE;
+ private int maximumLength = 32767;
private boolean password = false;
private String prompt = null;
private boolean editable = true;
View
5 wtk/src/org/apache/pivot/wtk/content/ButtonData.java
@@ -71,15 +71,16 @@ public void setIcon(URL iconURL) {
}
Image iconLocal = (Image)ApplicationContext.getResourceCache().get(iconURL);
-
if (iconLocal == null) {
try {
iconLocal = Image.load(iconURL);
+ ApplicationContext.getResourceCache().put(iconURL, iconLocal);
} catch (TaskExecutionException exception) {
throw new IllegalArgumentException(exception);
}
- ApplicationContext.getResourceCache().put(iconURL, iconLocal);
+ } else {
+ iconLocal.clearImageListeners();
}
setIcon(iconLocal);
View
4 wtk/src/org/apache/pivot/wtk/media/Image.java
@@ -139,6 +139,10 @@ public void update(int x, int y, int width, int height) {
return imageListeners;
}
+ public void clearImageListeners() {
+ this.imageListeners = new ImageListenerList();
+ }
+
public static Image load(URL location) throws TaskExecutionException {
LoadTask loadTask = new LoadTask(location);
return loadTask.execute();
View
32 wtk/src/org/apache/pivot/wtk/validation/BigDecimalValidator.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.wtk.validation;
+
+import java.math.BigDecimal;
+import java.util.Locale;
+
+/**
+ * A validator for a BigDecimal value.
+ */
+public class BigDecimalValidator extends ComparableValidator<BigDecimal> {
+
+ public BigDecimalValidator() {
+ super();
+ }
+
+ public BigDecimalValidator(Locale locale) {
+ super(locale);
+ }
+
+}
View
32 wtk/src/org/apache/pivot/wtk/validation/BigIntegerValidator.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.wtk.validation;
+
+import java.math.BigInteger;
+import java.util.Locale;
+
+/**
+ * A validator for a BigInteger value.
+ */
+public class BigIntegerValidator extends ComparableValidator<BigInteger> {
+
+ public BigIntegerValidator() {
+ super();
+ }
+
+ public BigIntegerValidator(Locale locale) {
+ super(locale);
+ }
+
+}
View
91 wtk/src/org/apache/pivot/wtk/validation/ComparableRangeValidator.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.wtk.validation;
+
+import java.util.Locale;
+
+/**
+ * Generic validator version for a Comparable value limited in a range.
+ */
+public class ComparableRangeValidator<T extends Comparable<T>> extends ComparableValidator<T> {
+ private T minValue;
+ private T maxValue;
+
+ public ComparableRangeValidator() {
+ this(Locale.getDefault());
+ }
+
+ public ComparableRangeValidator(Locale locale) {
+ super(locale);
+ this.minValue = null;
+ this.maxValue = null;
+ }
+
+ public ComparableRangeValidator(T minValue, T maxValue) {
+ this(Locale.getDefault(), minValue, maxValue);
+ }
+
+ public ComparableRangeValidator(Locale locale, T minValue, T maxValue) {
+ super(locale);
+ setMinimum(minValue);
+ setMaximum(maxValue);
+
+ if (maxValue.compareTo(minValue)< 0) {
+ throw new IllegalArgumentException("maxValue must be higher or equals than minValue");
+ }
+ }
+
+ public T getMinimum() {
+ return minValue;
+ }
+
+ public void setMinimum(T minValue) {
+ if (minValue == null) {
+ throw new IllegalArgumentException("minValue must be not null");
+ }
+ this.minValue = minValue;
+ }
+
+ public T getMaximum() {
+ return maxValue;
+ }
+
+ public void setMaximum(T maxValue) {
+ if (minValue == null) {
+ throw new IllegalArgumentException("minValue must be not null");
+ }
+ this.maxValue = maxValue;
+ }
+
+ @Override
+ public boolean isValid(String text) {
+ boolean valid = false;
+
+ if (super.isValid(text)) {
+ @SuppressWarnings("unchecked")
+ final Comparable<T> value = (Comparable<T>) textToComparable(text);
+ if (value != null) {
+ valid = (value.compareTo(minValue) >= 0 && value.compareTo(maxValue) <= 0);
+ }
+ }
+
+ return valid;
+ }
+
+ @Override
+ public String toString() {
+ return ( this.getClass().getSimpleName() + "(" + minValue + "," + maxValue + ")" );
+ }
+
+}
View
56 wtk/src/org/apache/pivot/wtk/validation/ComparableValidator.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.wtk.validation;
+
+import java.util.Locale;
+
+/**
+ * A validator for a Comparable value.
+ */
+public class ComparableValidator<T extends Comparable<T>> extends DecimalValidator {
+
+ public ComparableValidator() {
+ super();
+ }
+
+ public ComparableValidator(Locale locale) {
+ super(locale);
+ }
+
+// @Override
+// public boolean isValid(String text) {
+// if (!super.isValid(text))
+// return false;
+//
+// return true;
+// }
+
+ @Override
+ public boolean isValid(String text) {
+ boolean valid = false;
+
+ if (super.isValid(text)) {
+ @SuppressWarnings("unchecked")
+ final Comparable<T> value = (Comparable<T>) textToComparable(text);
+ valid = (value != null);
+ }
+
+ return valid;
+ }
+
+ protected final Comparable<?> textToComparable(String text) {
+ return (Comparable<?>) textToBigDecimal(text);
+ }
+
+}
View
35 wtk/src/org/apache/pivot/wtk/validation/DecimalValidator.java
@@ -13,6 +13,7 @@
*/
package org.apache.pivot.wtk.validation;
+import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;
@@ -22,6 +23,7 @@
* A validator for decimal values.
*/
public class DecimalValidator extends FormattedValidator<NumberFormat> {
+ private boolean autoTrim = false;
public DecimalValidator(DecimalFormat format) {
super(format);
@@ -43,11 +45,42 @@ public DecimalValidator(Locale locale) {
protected final Number parseNumber(String text) {
try {
// We have to upper case because of the exponent symbol
- text = (locale == null) ? text.toUpperCase() : text.toUpperCase(locale);
+ text = text.toUpperCase(locale);
return format.parse(text);
} catch (ParseException ex) {
// this should never happen
throw new RuntimeException(ex);
}
}
+
+ /** helper method that returns the widest number real instance,
+ * and extract later values depending on the precision needed.
+ */
+ protected final BigDecimal textToBigDecimal(String text) {
+ BigDecimal bd;
+ try {
+ if (!autoTrim) {
+ bd = new BigDecimal(parseNumber(text).toString());
+ } else {
+ bd = new BigDecimal(parseNumber(text.trim()).toString());
+ }
+ } catch (Exception e) {
+ // ignore it
+ bd = null;
+ }
+ return bd;
+ }
+
+ /** set the autoTrim mode, before parsing the text (default false) */
+ public void setAutoTrim(boolean autoTrim) {
+ this.autoTrim = autoTrim;
+ }
+
+ /** tell the autoTrim mode
+ * @return true if autoTrim is enabled, otherwise false (default)
+ * */
+ public boolean isAutoTrim() {
+ return autoTrim;
+ }
+
}
View
4 wtk/src/org/apache/pivot/wtk/validation/DoubleRangeValidator.java
@@ -17,6 +17,10 @@
/**
* A validator for a double value limited to a range.
+ * <p>
+ * Beware that usual math rules for native primitive types (and related approximations) are applied here.
+ *
+ * @see ComparableRangeValidator
*/
public class DoubleRangeValidator extends DoubleValidator {
private double minValue, maxValue;
View
6 wtk/src/org/apache/pivot/wtk/validation/DoubleValidator.java
@@ -13,12 +13,14 @@
*/
package org.apache.pivot.wtk.validation;
-import java.text.DecimalFormat;
-import java.text.DecimalFormatSymbols;
import java.util.Locale;
/**
* A validator for a double value.
+ * <p>
+ * Beware that usual math rules for native primitive types (and related approximations) are applied here.
+ *
+ * @see BigDecimalValidator
*/
public class DoubleValidator extends DecimalValidator {
View
31 wtk/src/org/apache/pivot/wtk/validation/EmptyTextValidator.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.wtk.validation;
+
+/**
+ * A validator for a (trimmed) text.
+ * <p>
+ * This is useful only when a value to be valid has to be absent.
+ */
+public class EmptyTextValidator implements Validator {
+
+ public EmptyTextValidator() {
+ }
+
+ @Override
+ public boolean isValid(String text) {
+ return (text.trim()).length() == 0;
+ }
+
+}
View
4 wtk/src/org/apache/pivot/wtk/validation/FloatRangeValidator.java
@@ -17,6 +17,10 @@
/**
* A validator for a float value limited to a range.
+ * <p>
+ * Beware that usual math rules for native primitive types (and related approximations) are applied here.
+ *
+ * @see ComparableRangeValidator
*/
public class FloatRangeValidator extends FloatValidator {
private float minValue, maxValue;
View
13 wtk/src/org/apache/pivot/wtk/validation/FloatValidator.java
@@ -13,12 +13,14 @@
*/
package org.apache.pivot.wtk.validation;
-import java.text.DecimalFormat;
-import java.text.DecimalFormatSymbols;
import java.util.Locale;
/**
* A validator for a float value.
+ * <p>
+ * Beware that usual math rules for native primitive types (and related approximations) are applied here.
+ *
+ * @see BigDecimalValidator
*/
public class FloatValidator extends DecimalValidator {
@@ -37,13 +39,12 @@ public boolean isValid(String text) {
/*
* DecimalFormat will parse the number as a double. Make sure the
- * resulting number is withing range for a float.
+ * resulting number is within range for a float.
*/
Number number = parseNumber(text);
double doubleValue = number.doubleValue();
- if (doubleValue == Double.POSITIVE_INFINITY ||
- doubleValue == Double.NEGATIVE_INFINITY ||
- doubleValue == Double.NaN) {
+ if (doubleValue == Double.POSITIVE_INFINITY || doubleValue == Double.NEGATIVE_INFINITY
+ || Double.isNaN(doubleValue)) {
return true;
}
doubleValue = Math.abs(doubleValue);
View
16 wtk/src/org/apache/pivot/wtk/validation/FormattedValidator.java
@@ -31,13 +31,21 @@
protected final Locale locale;
public FormattedValidator(F format) {
- this.format = format;
- this.locale = null;
+ this(format, null);
}
public FormattedValidator(F format, Locale locale) {
+ if (format == null) {
+ throw new IllegalArgumentException("format is null.");
+ }
this.format = format;
- this.locale = locale;
+
+ if (locale == null) {
+ this.locale = Locale.getDefault();
+ } else {
+ this.locale = locale;
+ }
+
}
@Override
@@ -45,7 +53,7 @@ public boolean isValid(String text) {
final ParsePosition pos = new ParsePosition(0);
if (format instanceof NumberFormat) {
// We have to upper case because of the exponent symbol
- text = (locale == null) ? text.toUpperCase() : text.toUpperCase(locale);
+ text = text.toUpperCase(locale);
}
Object obj = format.parseObject(text, pos);
View
4 wtk/src/org/apache/pivot/wtk/validation/IntRangeValidator.java
@@ -17,6 +17,10 @@
/**
* A validator for an int value limited to a range.
+ * <p>
+ * Beware that usual math rules for native primitive types (and related approximations) are applied here.
+ *
+ * @see ComparableRangeValidator
*/
public class IntRangeValidator extends IntValidator {
private int minValue, maxValue;
View
4 wtk/src/org/apache/pivot/wtk/validation/IntValidator.java
@@ -17,6 +17,10 @@
/**
* A validator for an int value.
+ * <p>
+ * Beware that usual math rules for native primitive types (and related approximations) are applied here.
+ *
+ * @see BigIntegerValidator
*/
public class IntValidator extends DecimalValidator {
public IntValidator() {
Please sign in to comment.
Something went wrong with that request. Please try again.