Cross Reference: bug4337267.java
xref
: /
openjdk7
/
jdk
/
test
/
javax
/
swing
/
JComponent
/
4337267
/
bug4337267.java
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
869
N/A
/*
869
N/A
* @test
869
N/A
* @bug 4337267
869
N/A
* @summary test that numeric shaping works in Swing components
869
N/A
* @author Sergey Groznyh
869
N/A
* @run main bug4337267
869
N/A
*/
869
N/A
869
N/A
import
java
.
awt
.
Component
;
869
N/A
import
java
.
awt
.
Dimension
;
869
N/A
import
java
.
awt
.
Graphics
;
869
N/A
import
java
.
awt
.
font
.
NumericShaper
;
869
N/A
import
java
.
awt
.
font
.
TextAttribute
;
869
N/A
import
java
.
awt
.
image
.
BufferedImage
;
869
N/A
import
javax
.
swing
.
BoxLayout
;
869
N/A
import
javax
.
swing
.
JComponent
;
869
N/A
import
javax
.
swing
.
JFrame
;
873
N/A
import
javax
.
swing
.
JLabel
;
869
N/A
import
javax
.
swing
.
JPanel
;
869
N/A
import
javax
.
swing
.
JTextArea
;
869
N/A
import
javax
.
swing
.
SwingUtilities
;
869
N/A
869
N/A
public
class
bug4337267
{
869
N/A
TestJPanel
p1
,
p2
;
869
N/A
TestBufferedImage
i1
,
i2
;
0
N/A
JComponent
[]
printq
;
0
N/A
JFrame
window
;
0
N/A
static
boolean
testFailed
=
false
;
0
N/A
static
boolean
done
=
false
;
869
N/A
0
N/A
String
shaped
=
0
N/A
"000 (E) 111 (A) \u0641\u0642\u0643 \u0662\u0662\u0662 (E) 333"
;
0
N/A
String
text
=
"000 (E) 111 (A) \u0641\u0642\u0643 222 (E) 333"
;
869
N/A
0
N/A
void
run
() {
869
N/A
initUI
();
0
N/A
testTextComponent
();
869
N/A
testNonTextComponentHTML
();
869
N/A
testNonTextComponentPlain
();
869
N/A
2624
N/A
doneTask
();
869
N/A
}
48
N/A
869
N/A
void
initUI
() {
0
N/A
window
=
new
JFrame
(
"bug4337267"
);
869
N/A
window
.
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
716
N/A
window
.
setSize
(
800
,
600
);
869
N/A
Component
content
=
createContentPane
();
1958
N/A
window
.
add
(
content
);
1963
N/A
window
.
setVisible
(
true
);
2340
N/A
}
1954
N/A
1954
N/A
Runnable
printComponents
=
new
Runnable
() {
1954
N/A
public
void
run
() {
1954
N/A
printComponent
(
printq
[
0
],
i1
);
1954
N/A
printComponent
(
printq
[
1
],
i2
);
1954
N/A
}
1954
N/A
};
1954
N/A
2350
N/A
Runnable
compareRasters
=
new
Runnable
() {
1954
N/A
public
void
run
() {
1954
N/A
assertEquals
(
p1
.
image
,
p2
.
image
);
1954
N/A
assertEquals
(
i1
,
i2
);
1954
N/A
}
0
N/A
};
0
N/A
869
N/A
void
doneTask
() {
868
N/A
final
Object
monitor
=
this
;
2624
N/A
SwingUtilities
.
invokeLater
(
new
Runnable
() {
2693
N/A
public
void
run
() {
2042
N/A
done
=
true
;
2982
N/A
synchronized
(
monitor
) {
1007
N/A
monitor
.
notify
();
2980
N/A
}
2963
N/A
}
1503
N/A
});
2915
N/A
}
869
N/A
2624
N/A
2624
N/A
void
fail
(
String
message
) {
0
N/A
testFailed
=
true
;
2270
N/A
throw
new
RuntimeException
(
message
);
2270
N/A
}
2270
N/A
2270
N/A
void
assertEquals
(
Object
o1
,
Object
o2
) {
2270
N/A
if
((
o1
==
null
) && (
o2
!=
null
)) {
2270
N/A
fail
(
"Expected null, got "
+
o2
);
2270
N/A
}
else
if
((
o1
!=
null
) && (
o2
==
null
)) {
0
N/A
fail
(
"Expected "
+
o1
+
", got null"
);
869
N/A
}
else
if
(!
o1
.
equals
(
o2
)) {
868
N/A
fail
(
"Expected "
+
o1
+
", got "
+
o2
);
0
N/A
}
0
N/A
}
65
N/A
869
N/A
void
testTextComponent
() {
868
N/A
System
.
out
.
println
(
"testTextComponent:"
);
65
N/A
JTextArea
area1
=
new
JTextArea
();
869
N/A
injectComponent
(
p1
,
area1
,
false
);
2624
N/A
area1
.
setText
(
shaped
);
2624
N/A
JTextArea
area2
=
new
JTextArea
();
65
N/A
injectComponent
(
p2
,
area2
,
true
);
65
N/A
area2
.
setText
(
text
);
65
N/A
window
.
repaint
();
65
N/A
printq
=
new
JComponent
[] {
area1
,
area2
};
65
N/A
SwingUtilities
.
invokeLater
(
printComponents
);
65
N/A
SwingUtilities
.
invokeLater
(
compareRasters
);
65
N/A
}
65
N/A
65
N/A
void
testNonTextComponentHTML
() {
65
N/A
System
.
out
.
println
(
"testNonTextComponentHTML:"
);
65
N/A
JLabel
label1
=
new
JLabel
();
65
N/A
injectComponent
(
p1
,
label1
,
false
);
65
N/A
label1
.
setText
(
"<html>"
+
shaped
);
2266
N/A
JLabel
label2
=
new
JLabel
();
2266
N/A
injectComponent
(
p2
,
label2
,
true
);
2266
N/A
label2
.
setText
(
"<html>"
+
text
);
2266
N/A
window
.
repaint
();
2266
N/A
printq
=
new
JComponent
[] {
label1
,
label2
};
2624
N/A
SwingUtilities
.
invokeLater
(
printComponents
);
2624
N/A
SwingUtilities
.
invokeLater
(
compareRasters
);
2266
N/A
}
2266
N/A
2624
N/A
void
testNonTextComponentPlain
() {
2266
N/A
System
.
out
.
println
(
"testNonTextComponentHTML:"
);
2266
N/A
JLabel
label1
=
new
JLabel
();
2266
N/A
injectComponent
(
p1
,
label1
,
false
);
2266
N/A
label1
.
setText
(
shaped
);
2266
N/A
JLabel
label2
=
new
JLabel
();
2266
N/A
injectComponent
(
p2
,
label2
,
true
);
2266
N/A
label2
.
setText
(
text
);
2266
N/A
window
.
repaint
();
2266
N/A
printq
=
new
JComponent
[] {
label1
,
label2
};
2266
N/A
SwingUtilities
.
invokeLater
(
printComponents
);
2266
N/A
SwingUtilities
.
invokeLater
(
compareRasters
);
2266
N/A
}
2266
N/A
2266
N/A
void
setShaping
(
JComponent
c) {
2266
N/A
c.
putClientProperty
(
TextAttribute
.
NUMERIC_SHAPING
,
2266
N/A
NumericShaper
.
getContextualShaper
(
NumericShaper
.
ARABIC
));
2266
N/A
}
2266
N/A
2266
N/A
void
injectComponent
(
JComponent
p,
JComponent
c,
boolean
shape
) {
2266
N/A
if
(
shape
) {
2266
N/A
setShaping
(c);
2266
N/A
}
2266
N/A
p.
removeAll
();
2266
N/A
p.
add
(c);
2266
N/A
}
0
N/A
869
N/A
void
printComponent
(
JComponent
c,
TestBufferedImage
i) {
868
N/A
Graphics
g = i.
getGraphics
();
0
N/A
g.
setColor
(c.
getBackground
());
0
N/A
g.
fillRect
(
0
,
0
, i.
getWidth
(), i.
getHeight
());
0
N/A
c.
print
(g);
0
N/A
}
0
N/A
2334
N/A
Component
createContentPane
() {
0
N/A
Dimension
size
=
new
Dimension
(
500
,
100
);
2624
N/A
i1
=
new
TestBufferedImage
(
size
.
width
,
size
.
height
,
2624
N/A
BufferedImage
.
TYPE_INT_ARGB
);
0
N/A
i2
=
new
TestBufferedImage
(
size
.
width
,
size
.
height
,
0
N/A
BufferedImage
.
TYPE_INT_ARGB
);
869
N/A
p1
=
new
TestJPanel
();
868
N/A
p1
.
setPreferredSize
(
size
);
0
N/A
p2
=
new
TestJPanel
();
0
N/A
p2
.
setPreferredSize
(
size
);
869
N/A
JPanel
panel
=
new
JPanel
();
0
N/A
panel
.
setLayout
(
new
BoxLayout
(
panel
,
BoxLayout
.
Y_AXIS
));
0
N/A
panel
.
add
(
p1
);
2624
N/A
panel
.
add
(
p2
);
2624
N/A
2624
N/A
return
panel
;
869
N/A
}
2624
N/A
2624
N/A
static
class
TestBufferedImage
extends
BufferedImage
{
2624
N/A
int
MAX_GLITCHES
=
0
;
2624
N/A
2624
N/A
TestBufferedImage
(
int
width
,
int
height
,
int
imageType
) {
2624
N/A
super
(
width
,
height
,
imageType
);
2624
N/A
}
2624
N/A
2624
N/A
@
Override
2624
N/A
public
boolean
equals
(
Object
other
) {
2624
N/A
if
(! (
other
instanceof
TestBufferedImage
)) {
2624
N/A
return
false
;
2624
N/A
}
2624
N/A
TestBufferedImage
image2
= (
TestBufferedImage
)
other
;
2624
N/A
int
width
=
getWidth
();
2624
N/A
int
height
=
getHeight
();
2624
N/A
if
((
image2
.
getWidth
() !=
width
) || (
image2
.
getHeight
() !=
height
)) {
2624
N/A
return
false
;
2624
N/A
}
2624
N/A
int
glitches
=
0
;
2624
N/A
for
(
int
x =
0
; x <
width
; x++) {
2624
N/A
for
(
int
y =
0
; y <
height
; y++) {
2624
N/A
int
rgb1
=
getRGB
(x, y);
2624
N/A
int
rgb2
=
image2
.
getRGB
(x, y);
2624
N/A
if
(
rgb1
!=
rgb2
) {
2624
N/A
//System.out.println(x+" "+y+" "+rgb1+" "+rgb2);
2624
N/A
glitches
++;
2624
N/A
}
2624
N/A
}
2624
N/A
}
2624
N/A
return
glitches
<=
MAX_GLITCHES
;
0
N/A
}
0
N/A
}
869
N/A
868
N/A
static
class
TestJPanel
extends
JPanel
{
0
N/A
TestBufferedImage
image
=
createImage
(
new
Dimension
(
1
,
1
));
0
N/A
2624
N/A
TestBufferedImage
createImage
(
Dimension
d) {
848
N/A
return
new
TestBufferedImage
(d.
width
, d.
height
,
2624
N/A
BufferedImage
.
TYPE_INT_ARGB
);
2624
N/A
}
868
N/A
848
N/A
public
void
setPreferredSize
(
Dimension
size
) {
2624
N/A
super
.
setPreferredSize
(
size
);
0
N/A
image
=
createImage
(
size
);
2624
N/A
}
2624
N/A
0
N/A
public
void
paint
(
Graphics
g) {
0
N/A
Graphics
g0
=
image
.
getGraphics
();
868
N/A
super
.
paint
(
g0
);
2624
N/A
g.
drawImage
(
image
,
0
,
0
,
this
);
2222
N/A
}
2624
N/A
}
2624
N/A
2222
N/A
2222
N/A
2624
N/A
public
static
void
main
(
String
[]
args
)
throws
Throwable
{
2222
N/A
final
bug4337267
test
=
new
bug4337267
();
2624
N/A
SwingUtilities
.
invokeLater
(
new
Runnable
() {
2624
N/A
public
void
run
() {
2222
N/A
test
.
run
();
2222
N/A
}
2624
N/A
});
868
N/A
2624
N/A
synchronized
(
test
) {
2624
N/A
while
(!
done
) {
115
N/A
try
{
868
N/A
test
.
wait
();
868
N/A
}
catch
(
InterruptedException
ex
) {
2624
N/A
// do nothing
868
N/A
}
2624
N/A
}
2624
N/A
}
868
N/A
868
N/A
if
(
testFailed
) {
868
N/A
throw
new
RuntimeException
(
"FAIL"
);
2624
N/A
}
868
N/A
2624
N/A
System
.
out
.
println
(
"OK"
);
2624
N/A
}
868
N/A
}
868
N/A