Skip to content

Commit feb0b8b

Browse files
author
Sandro Martini
committed
merge some fixes from 2.0.x
git-svn-id: https://svn.apache.org/repos/asf/pivot/trunk@1446824 13f79535-47bb-0310-9956-ffa450edef68
1 parent d2b2427 commit feb0b8b

30 files changed

+955
-47
lines changed

build.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ limitations under the License.
308308
<javadoc packagenames="@{package}"
309309
destdir="${folder.doc}/@{jarFile}"
310310
author="true" version="true" use="true"
311-
package="true"
311+
package="true"
312312
classpath="${java.class.path}">
313313
<classpath>
314314
<path refid="classpath.general"/>

examples/.classpath

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<classpath>
33
<classpathentry kind="src" path="src"/>
44
<classpathentry kind="src" path="test"/>
5-
<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
65
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
76
<classpathentry combineaccessrules="false" kind="src" path="/core"/>
87
<classpathentry combineaccessrules="false" kind="src" path="/web"/>

examples/.project

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
2-
<projectDescription>
3-
<name>examples</name>
4-
<comment></comment>
5-
<projects>
6-
</projects>
7-
<buildSpec>
8-
<buildCommand>
9-
<name>org.scala-ide.sdt.core.scalabuilder</name>
10-
<arguments>
11-
</arguments>
12-
</buildCommand>
13-
</buildSpec>
14-
<natures>
15-
<nature>org.scala-ide.sdt.core.scalanature</nature>
16-
<nature>org.eclipse.jdt.core.javanature</nature>
17-
</natures>
18-
</projectDescription>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>examples</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//
2+
// README for org.apache.pivot.examples.scripting Samples
3+
//
4+
5+
In this package there are some Groovy sources and even some Scala sources, but in our ant builds they are not compiled.
6+
To run those examples from an IDE (like Eclipse), you must enable support for those languages for the project containing them (examples).
7+
8+
Note that in case of problems, for example a configured Nature for that project but the related Plugin is not installed,
9+
it will not be possible to run even Java examples because nothing in that project will be compiled.
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to you under the Apache License,
6+
* Version 2.0 (the "License"); you may not use this file except in
7+
* compliance with the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.pivot.tests;
18+
19+
import java.awt.Color;
20+
import java.awt.Font;
21+
import java.awt.GraphicsEnvironment;
22+
import java.awt.Toolkit;
23+
import java.awt.geom.AffineTransform;
24+
25+
import org.apache.pivot.collections.Map;
26+
import org.apache.pivot.wtk.Application;
27+
import org.apache.pivot.wtk.DesktopApplicationContext;
28+
import org.apache.pivot.wtk.Display;
29+
import org.apache.pivot.wtk.HorizontalAlignment;
30+
import org.apache.pivot.wtk.Label;
31+
import org.apache.pivot.wtk.VerticalAlignment;
32+
import org.apache.pivot.wtk.Window;
33+
34+
public class LabelAntialiasTest extends Application.Adapter {
35+
private Window window = null;
36+
37+
private Label buildLabel(double rotation) {
38+
Label label = new Label();
39+
40+
Font font = new Font("Arial", Font.BOLD, 64);
41+
42+
AffineTransform fontAT = new AffineTransform();
43+
// Derive a new font using a rotation transform
44+
fontAT.rotate(rotation * java.lang.Math.PI / 180.0d);
45+
Font fontDerived = font.deriveFont(fontAT);
46+
47+
label.setText("Hello at " + rotation + " degree.");
48+
label.getStyles().put("color", Color.RED);
49+
label.getStyles().put("font", fontDerived);
50+
label.getStyles().put("horizontalAlignment", HorizontalAlignment.CENTER);
51+
label.getStyles().put("verticalAlignment", VerticalAlignment.TOP);
52+
53+
return label;
54+
}
55+
56+
/**
57+
* Write to console some details of Desktop Hints, for Font Rendering.
58+
*
59+
* @see org.apache.pivot.wtk.Platform#initializeFontRenderContext
60+
*/
61+
private void showFontDesktopHints() {
62+
System.out.println("Show Font Desktop Hints:");
63+
64+
Toolkit toolkit = Toolkit.getDefaultToolkit();
65+
java.util.Map<?, ?> fontDesktopHints =
66+
(java.util.Map<?, ?>)toolkit.getDesktopProperty("awt.font.desktophints");
67+
68+
System.out.println(fontDesktopHints);
69+
}
70+
71+
/**
72+
* Write to console the list of Font families found in the System.
73+
*/
74+
private void showFontFamilies() {
75+
System.out.println("Show Font Families:");
76+
77+
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
78+
String []fontFamilies = ge.getAvailableFontFamilyNames();
79+
int fontFamiliesNumber = fontFamilies.length;
80+
StringBuffer fontFamilyNames = new StringBuffer(1024);
81+
for (int i=0; i < fontFamiliesNumber; i++) {
82+
if (i > 0) {
83+
fontFamilyNames.append(", ");
84+
}
85+
fontFamilyNames.append(fontFamilies[i]);
86+
}
87+
System.out.println(fontFamilyNames);
88+
}
89+
90+
@Override
91+
public void startup(Display display, Map<String, String> properties) {
92+
window = new Window();
93+
94+
showFontDesktopHints();
95+
showFontFamilies();
96+
97+
Label label = buildLabel(45);
98+
window.setContent(label);
99+
100+
window.setTitle("Label Antialiasing Test");
101+
window.setMaximized(true);
102+
window.open(display);
103+
}
104+
105+
@Override
106+
public boolean shutdown(boolean optional) {
107+
if (window != null) {
108+
window.close();
109+
}
110+
111+
return false;
112+
}
113+
114+
public static void main(String[] args) {
115+
DesktopApplicationContext.main(LabelAntialiasTest.class, args);
116+
}
117+
118+
}

tests/src/org/apache/pivot/tests/TextInputValidatorTest.java

Lines changed: 83 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
*/
1414
package org.apache.pivot.tests;
1515

16+
// import java.text.DecimalFormat;
17+
import java.math.BigDecimal;
18+
import java.text.NumberFormat;
19+
import java.util.Locale;
20+
1621
import org.apache.pivot.beans.BXMLSerializer;
1722
import org.apache.pivot.collections.Map;
1823
import org.apache.pivot.wtk.Application;
@@ -23,19 +28,29 @@
2328
import org.apache.pivot.wtk.TextInput;
2429
import org.apache.pivot.wtk.TextInputListener;
2530
import org.apache.pivot.wtk.Window;
31+
import org.apache.pivot.wtk.validation.BigDecimalValidator;
32+
import org.apache.pivot.wtk.validation.ComparableRangeValidator;
2633
import org.apache.pivot.wtk.validation.DoubleValidator;
27-
import org.apache.pivot.wtk.validation.FloatValidator;
34+
import org.apache.pivot.wtk.validation.EmptyTextValidator;
2835
import org.apache.pivot.wtk.validation.FloatRangeValidator;
36+
import org.apache.pivot.wtk.validation.FloatValidator;
2937
import org.apache.pivot.wtk.validation.IntRangeValidator;
3038
import org.apache.pivot.wtk.validation.NotEmptyTextValidator;
3139
import org.apache.pivot.wtk.validation.RegexTextValidator;
3240
import org.apache.pivot.wtk.validation.Validator;
41+
// import java.util.Formatter;
3342

3443
/**
3544
* Text input validator test.
3645
*/
3746
public class TextInputValidatorTest extends Application.Adapter {
47+
private Locale locale = Locale.getDefault(); // the default locale
48+
3849
private Window window = null;
50+
private TextInput textinputLocale = null;
51+
private TextInput textinputComparableBigDecimal = null;
52+
private TextInput textinputComparableRange = null;
53+
private Label invalidComparableRangeLabel = null;
3954
private TextInput textinputDouble = null;
4055
private TextInput textinputFloat = null;
4156
private TextInput textinputFloatRange = null;
@@ -44,30 +59,89 @@ public class TextInputValidatorTest extends Application.Adapter {
4459
private TextInput textinputDateRegex = null;
4560
private TextInput textinputCustomBoolean = null;
4661
private TextInput textinputNotEmptyText = null;
62+
private TextInput textinputEmptyText = null;
4763

4864
@Override
4965
public void startup(Display display, Map<String, String> properties) throws Exception {
66+
System.out.println("Starting TextInputValidatorTest ...");
67+
System.out.println("current Locale is " + locale);
68+
69+
// sample different ways to format numbers in i18n compatible way
70+
NumberFormat nf = NumberFormat.getInstance();
71+
//
72+
// String customDecimalPattern = ""###,###.###"";
73+
// DecimalFormat df = new DecimalFormat(customDecimalPattern);
74+
//
75+
// StringBuffer sb = new StringBuffer();
76+
// Formatter formatter = new Formatter(sb, locale);
77+
// String customDecimalFormat = "%,.3f";
78+
//
79+
5080
BXMLSerializer bxmlSerializer = new BXMLSerializer();
5181
window = new Window((Component)bxmlSerializer.readObject(
5282
getClass().getResource("text_input_validator_test.bxml")));
5383

84+
textinputLocale = (TextInput)bxmlSerializer.getNamespace().get("textinputLocale");
85+
86+
textinputComparableBigDecimal = (TextInput)bxmlSerializer.getNamespace().get("textinputComparableBigDecimal");
87+
textinputComparableRange = (TextInput)bxmlSerializer.getNamespace().get("textinputComparableRange");
5488
textinputDouble = (TextInput)bxmlSerializer.getNamespace().get("textinputDouble");
5589
textinputFloat = (TextInput)bxmlSerializer.getNamespace().get("textinputFloat");
5690
textinputFloatRange = (TextInput)bxmlSerializer.getNamespace().get("textinputFloatRange");
5791
textinputIntRange = (TextInput)bxmlSerializer.getNamespace().get("textinputIntRange");
5892
textinputDateRegex = (TextInput)bxmlSerializer.getNamespace().get("textinputDateRegex");
5993
textinputCustomBoolean = (TextInput)bxmlSerializer.getNamespace().get("textinputCustomBoolean");
6094
textinputNotEmptyText = (TextInput)bxmlSerializer.getNamespace().get("textinputNotEmptyText");
95+
textinputEmptyText = (TextInput)bxmlSerializer.getNamespace().get("textinputEmptyText");
96+
97+
textinputLocale.setText(locale.toString());
98+
99+
String testValue = "123456789.0";
100+
// new, validate a value but using BigDecimalValidator (subclass of ComparableValidator)
101+
textinputComparableBigDecimal.setText("1e300"); // huge value, and outside double range ...
102+
BigDecimalValidator bdComp = new BigDecimalValidator();
103+
System.out.println("BigDecimalValidator: created instance with value: " + bdComp);
104+
bdComp.setAutoTrim(true); // enable auto-trim of input string, before validating
105+
System.out.println("BigDecimalValidator: enable auto-trim of input string, before validating");
106+
textinputComparableBigDecimal.setValidator(bdComp);
107+
108+
// new, validate in a range but using ComparableRangeValidator
109+
textinputComparableRange.setText(nf.format(new BigDecimal(testValue)));
110+
ComparableRangeValidator<BigDecimal> bdCompRange = new ComparableRangeValidator<BigDecimal>(
111+
new BigDecimal("2.0"), new BigDecimal("123456789")
112+
);
113+
System.out.println("ComparableRangeValidator: created instance with value: " + bdCompRange);
114+
bdCompRange.setAutoTrim(true); // enable auto-trim of input string, before validating
115+
System.out.println("ComparableRangeValidator: enable auto-trim of input string, before validating");
116+
textinputComparableRange.setValidator(bdCompRange);
117+
textinputComparableRange.getTextInputListeners().add(new TextInputListener.Adapter() {
118+
@Override
119+
public void textValidChanged(TextInput textInput) {
120+
invalidComparableRangeLabel.setText(textInput.isTextValid() ? "valid" : "invalid");
121+
}
122+
});
123+
invalidComparableRangeLabel = (Label)bxmlSerializer.getNamespace().get("invalidComparableRangeLabel");
61124

62-
textinputDouble.setText("\u221E");
125+
textinputDouble.setText("\u221E"); // infinite symbol
63126
textinputDouble.setValidator(new DoubleValidator());
64127

65-
textinputFloat.setText("1.5");
128+
// textinputFloat.setText("123456.789");
129+
// new, show different ways to format decimal values in i18n format
130+
Double value = new Double(testValue);
131+
// textinputFloat.setText(value.toString());
132+
// textinputFloat.setText(String.format(customDecimalFormat, value)); // sample using String.format
133+
// formatter.format(customDecimalFormat, value); // sample using Formatter
134+
// textinputFloat.setText(sb.toString()); // sample using Formatter
135+
// textinputFloat.setText(nf.format(value)); // sample using NumberFormat
136+
// textinputFloat.setText(df.format(value)); // sample using DecimalFormat
137+
textinputFloat.setText(nf.format(value)); // using this as a sample
66138
textinputFloat.setValidator(new FloatValidator());
67139

68140
// standard float range model
69-
textinputFloatRange.setText("0.5");
70-
textinputFloatRange.setValidator(new FloatRangeValidator(0.3f, 2000f));
141+
// note that float approximations could give errors,
142+
// try to increment/decrement the initial value near a range end, to see problems ...
143+
textinputFloatRange.setText(nf.format(new Float(testValue)));
144+
textinputFloatRange.setValidator(new FloatRangeValidator(2.0f, 123456789f));
71145

72146
// test the listener by updating a label
73147
textinputFloatRange.getTextInputListeners().add(new TextInputListener.Adapter() {
@@ -101,6 +175,10 @@ public boolean isValid(String s) {
101175
textinputNotEmptyText.setText(" Not Empty, and with spaces ");
102176
textinputNotEmptyText.setValidator(new NotEmptyTextValidator());
103177

178+
// validate any empty text, edge case
179+
textinputEmptyText.setText(" ");
180+
textinputEmptyText.setValidator(new EmptyTextValidator());
181+
104182

105183
window.setTitle("Text Input Validator Test");
106184
window.setMaximized(true);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to you under the Apache License,
7+
Version 2.0 (the "License"); you may not use this file except in
8+
compliance with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
19+
<Window title="Pivot-880" maximized="true"
20+
bxml:id="window"
21+
xmlns:bxml="http://pivot.apache.org/bxml"
22+
xmlns="org.apache.pivot.wtk"
23+
>
24+
25+
<Form>
26+
<Form.Section>
27+
<TextInput bxml:id="textInput" text="${textArea.text}"/>
28+
<Border>
29+
<FillPane minimumWidth="300" minimumHeight="100">
30+
<TextArea bxml:id="textArea" text="${textInput.text}"/>
31+
</FillPane>
32+
</Border>
33+
</Form.Section>
34+
</Form>
35+
36+
</Window>

0 commit comments

Comments
 (0)