Skip to content

Commit

Permalink
merge some fixes from 2.0.x
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/pivot/trunk@1446824 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Sandro Martini committed Feb 16, 2013
1 parent d2b2427 commit feb0b8b
Show file tree
Hide file tree
Showing 30 changed files with 955 additions and 47 deletions.
2 changes: 1 addition & 1 deletion build.xml
Expand Up @@ -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"/>
Expand Down
1 change: 0 additions & 1 deletion examples/.classpath
Expand Up @@ -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"/>
Expand Down
35 changes: 17 additions & 18 deletions 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>
9 changes: 9 additions & 0 deletions 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.
118 changes: 118 additions & 0 deletions 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);
}

}
88 changes: 83 additions & 5 deletions tests/src/org/apache/pivot/tests/TextInputValidatorTest.java
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -44,30 +59,89 @@ public class TextInputValidatorTest extends Application.Adapter {
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");
textinputIntRange = (TextInput)bxmlSerializer.getNamespace().get("textinputIntRange");
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() {
Expand Down Expand Up @@ -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);
Expand Down
36 changes: 36 additions & 0 deletions 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>

0 comments on commit feb0b8b

Please sign in to comment.