Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
e3f7ed07
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
e3f7ed07
编写于
1月 09, 2020
作者:
P
pbansal
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8224475: JTextPane does not show images in HTML rendering
Reviewed-by: serb, psadhukhan
上级
371694d6
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
193 addition
and
12 deletion
+193
-12
src/share/classes/javax/swing/text/html/ImageView.java
src/share/classes/javax/swing/text/html/ImageView.java
+20
-12
test/javax/swing/JTextPane/TestJTextPaneHTMLRendering.java
test/javax/swing/JTextPane/TestJTextPaneHTMLRendering.java
+173
-0
test/javax/swing/JTextPane/arrow.png
test/javax/swing/JTextPane/arrow.png
+0
-0
未找到文件。
src/share/classes/javax/swing/text/html/ImageView.java
浏览文件 @
e3f7ed07
...
@@ -734,6 +734,22 @@ public class ImageView extends View {
...
@@ -734,6 +734,22 @@ public class ImageView extends View {
newState
|=
HEIGHT_FLAG
;
newState
|=
HEIGHT_FLAG
;
}
}
Image
img
;
synchronized
(
this
)
{
img
=
image
;
}
if
(
newWidth
<=
0
)
{
newWidth
=
img
.
getWidth
(
imageObserver
);
if
(
newWidth
<=
0
)
{
newWidth
=
DEFAULT_WIDTH
;
}
}
if
(
newHeight
<=
0
)
{
newHeight
=
img
.
getHeight
(
imageObserver
);
if
(
newHeight
<=
0
)
{
newHeight
=
DEFAULT_HEIGHT
;
}
}
/*
/*
If synchronous loading flag is set, then make sure that the image is
If synchronous loading flag is set, then make sure that the image is
scaled appropriately.
scaled appropriately.
...
@@ -741,18 +757,10 @@ public class ImageView extends View {
...
@@ -741,18 +757,10 @@ public class ImageView extends View {
appropriately.
appropriately.
*/
*/
if
(
getLoadsSynchronously
())
{
if
(
getLoadsSynchronously
())
{
Image
img
;
Dimension
d
=
adjustWidthHeight
(
newWidth
,
newHeight
);
synchronized
(
this
)
{
newWidth
=
d
.
width
;
img
=
image
;
newHeight
=
d
.
height
;
}
newState
|=
(
WIDTH_FLAG
|
HEIGHT_FLAG
);
int
w
=
img
.
getWidth
(
imageObserver
);
int
h
=
img
.
getHeight
(
imageObserver
);
if
(
w
>
0
&&
h
>
0
)
{
Dimension
d
=
adjustWidthHeight
(
w
,
h
);
newWidth
=
d
.
width
;
newHeight
=
d
.
height
;
newState
|=
(
WIDTH_FLAG
|
HEIGHT_FLAG
);
}
}
}
// Make sure the image starts loading:
// Make sure the image starts loading:
...
...
test/javax/swing/JTextPane/TestJTextPaneHTMLRendering.java
0 → 100644
浏览文件 @
e3f7ed07
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code 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 Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8224475
* @summary Verify that JTextPane renders images properly for HTML text
* @run main/manual TestJTextPaneHTMLRendering
*/
import
java.awt.BorderLayout
;
import
java.awt.Color
;
import
java.awt.GridBagConstraints
;
import
java.awt.GridBagLayout
;
import
java.awt.event.ActionEvent
;
import
java.awt.event.WindowAdapter
;
import
java.awt.event.WindowEvent
;
import
java.awt.Image
;
import
java.net.URL
;
import
java.util.Dictionary
;
import
java.util.Hashtable
;
import
javax.swing.JButton
;
import
javax.swing.JTextArea
;
import
javax.swing.ImageIcon
;
import
javax.swing.JFrame
;
import
javax.swing.JPanel
;
import
javax.swing.JTextPane
;
import
javax.swing.text.EditorKit
;
import
javax.swing.SwingUtilities
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.TimeUnit
;
public
class
TestJTextPaneHTMLRendering
{
private
static
JFrame
mainFrame
=
new
JFrame
();
private
static
Dictionary
<
URL
,
Image
>
cache
;
private
static
JTextPane
textPane
;
private
static
URL
urlArrow
;
private
static
volatile
boolean
testResult
=
false
;
private
static
volatile
CountDownLatch
countDownLatch
;
private
static
final
String
INSTRUCTIONS
=
"INSTRUCTIONS:\n\n"
+
"Verify that the JTextPane is filled with green arrow images.\n"
+
"There should be 200 images (10 rows of 20 images each).\n"
+
"This test will run for 10 iterations and the current iteration\n"
+
"is being displayed at top of JTextPane. JTextpane will be\n"
+
"repainted each time and should have same output\n"
+
"If yes, Press Pass, Otherwise, Press Fail.\n"
;
public
static
void
main
(
String
args
[])
throws
Exception
{
urlArrow
=
new
URL
(
"http:\\arrow.png"
);
countDownLatch
=
new
CountDownLatch
(
1
);
SwingUtilities
.
invokeLater
(
TestJTextPaneHTMLRendering:
:
createUI
);
countDownLatch
.
await
(
15
,
TimeUnit
.
MINUTES
);
SwingUtilities
.
invokeLater
(
mainFrame:
:
dispose
);
if
(!
testResult
)
{
throw
new
RuntimeException
(
"Test failed!"
);
}
}
private
static
void
createUI
()
{
JPanel
mainControlPanel
=
new
JPanel
(
new
BorderLayout
(
20
,
20
));
JPanel
resultButtonPanel
=
new
JPanel
(
new
GridBagLayout
());
createTestUI
(
mainControlPanel
);
JTextArea
instructionTextArea
=
new
JTextArea
();
instructionTextArea
.
setText
(
INSTRUCTIONS
);
instructionTextArea
.
setEditable
(
false
);
instructionTextArea
.
setBackground
(
Color
.
white
);
mainControlPanel
.
add
(
instructionTextArea
,
BorderLayout
.
NORTH
);
JButton
passButton
=
new
JButton
(
"Pass"
);
passButton
.
setActionCommand
(
"Pass"
);
passButton
.
addActionListener
((
ActionEvent
e
)
->
{
testResult
=
true
;
countDownLatch
.
countDown
();
});
JButton
failButton
=
new
JButton
(
"Fail"
);
failButton
.
setActionCommand
(
"Fail"
);
failButton
.
addActionListener
(
e
->
{
countDownLatch
.
countDown
();
});
GridBagConstraints
gbc
=
new
GridBagConstraints
();
gbc
.
gridx
=
0
;
gbc
.
gridy
=
0
;
resultButtonPanel
.
add
(
passButton
,
gbc
);
gbc
.
gridx
=
1
;
gbc
.
gridy
=
0
;
resultButtonPanel
.
add
(
failButton
,
gbc
);
mainControlPanel
.
add
(
resultButtonPanel
,
BorderLayout
.
SOUTH
);
mainFrame
.
add
(
mainControlPanel
);
mainFrame
.
pack
();
mainFrame
.
addWindowListener
(
new
WindowAdapter
()
{
@Override
public
void
windowClosing
(
WindowEvent
e
)
{
mainFrame
.
dispose
();
countDownLatch
.
countDown
();
}
});
mainFrame
.
setVisible
(
true
);
}
static
void
createTestUI
(
JPanel
panel
)
{
textPane
=
new
JTextPane
();
panel
.
add
(
textPane
,
BorderLayout
.
CENTER
);
final
EditorKit
l_kit
=
textPane
.
getEditorKitForContentType
(
"text/html"
);
textPane
.
setEditable
(
false
);
textPane
.
setEditorKit
(
l_kit
);
cache
=
(
Dictionary
<
URL
,
Image
>)
textPane
.
getDocument
().
getProperty
(
"imageCache"
);
if
(
cache
==
null
)
{
cache
=
new
Hashtable
<
URL
,
Image
>();
textPane
.
getDocument
().
putProperty
(
"imageCache"
,
cache
);
}
URL
arrowLocationUrl
=
TestJTextPaneHTMLRendering
.
class
.
getResource
(
"arrow.png"
);
ImageIcon
imageIcon
=
new
ImageIcon
(
arrowLocationUrl
);
Image
image
=
imageIcon
.
getImage
();
Image
scaledImage
=
image
.
getScaledInstance
(
24
,
24
,
java
.
awt
.
Image
.
SCALE_SMOOTH
);
cache
.
put
(
urlArrow
,
scaledImage
);
new
Thread
(
TestJTextPaneHTMLRendering:
:
runTest
).
start
();
}
static
void
runTest
()
{
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
StringBuffer
sb
=
new
StringBuffer
();
sb
.
append
(
"<html><body bgcolor=\"#BBBBBB\"><center>Iteration "
+
(
i
+
1
)
+
" -> "
+
"<br>"
);
for
(
int
j
=
1
;
j
<
201
;
j
++)
{
sb
.
append
(
"<img src=\""
+
urlArrow
+
"\">"
);
if
(
j
%
20
==
0
)
sb
.
append
(
"<br>"
);
}
textPane
.
setText
(
sb
.
toString
());
textPane
.
validate
();
textPane
.
repaint
();
try
{
Thread
.
currentThread
().
sleep
(
1000
);
}
catch
(
InterruptedException
e
)
{
System
.
err
.
println
(
e
);
}
}
}
}
test/javax/swing/JTextPane/arrow.png
0 → 100644
浏览文件 @
e3f7ed07
6.1 KB
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录