Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
5bd32ca4
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看板
提交
5bd32ca4
编写于
2月 15, 2013
作者:
D
dingxmin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8008289: DefaultButtonModel instance keeps stale listeners in html FormView
Reviewed-by: malenkov, alexsch
上级
bc91f267
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
200 addition
and
1 deletion
+200
-1
src/share/classes/javax/swing/text/html/FormView.java
src/share/classes/javax/swing/text/html/FormView.java
+62
-1
test/javax/swing/text/html/7189299/bug7189299.java
test/javax/swing/text/html/7189299/bug7189299.java
+138
-0
未找到文件。
src/share/classes/javax/swing/text/html/FormView.java
浏览文件 @
5bd32ca4
...
...
@@ -159,6 +159,10 @@ public class FormView extends ComponentView implements ActionListener {
attr
.
getAttribute
(
StyleConstants
.
NameAttribute
);
JComponent
c
=
null
;
Object
model
=
attr
.
getAttribute
(
StyleConstants
.
ModelAttribute
);
// Remove listeners previously registered in shared model
// when a new UI component is replaced. See bug 7189299.
removeStaleListenerForModel
(
model
);
if
(
t
==
HTML
.
Tag
.
INPUT
)
{
c
=
createInputComponent
(
attr
,
model
);
}
else
if
(
t
==
HTML
.
Tag
.
SELECT
)
{
...
...
@@ -310,6 +314,63 @@ public class FormView extends ComponentView implements ActionListener {
return
c
;
}
private
void
removeStaleListenerForModel
(
Object
model
)
{
if
(
model
instanceof
DefaultButtonModel
)
{
// case of JButton whose model is DefaultButtonModel
// Need to remove stale ActionListener, ChangeListener and
// ItemListener that are instance of AbstractButton$Handler.
DefaultButtonModel
buttonModel
=
(
DefaultButtonModel
)
model
;
String
listenerClass
=
"javax.swing.AbstractButton$Handler"
;
for
(
ActionListener
listener
:
buttonModel
.
getActionListeners
())
{
if
(
listenerClass
.
equals
(
listener
.
getClass
().
getName
()))
{
buttonModel
.
removeActionListener
(
listener
);
}
}
for
(
ChangeListener
listener
:
buttonModel
.
getChangeListeners
())
{
if
(
listenerClass
.
equals
(
listener
.
getClass
().
getName
()))
{
buttonModel
.
removeChangeListener
(
listener
);
}
}
for
(
ItemListener
listener
:
buttonModel
.
getItemListeners
())
{
if
(
listenerClass
.
equals
(
listener
.
getClass
().
getName
()))
{
buttonModel
.
removeItemListener
(
listener
);
}
}
}
else
if
(
model
instanceof
AbstractListModel
)
{
// case of JComboBox and JList
// For JList, the stale ListDataListener is instance
// BasicListUI$Handler.
// For JComboBox, there are 2 stale ListDataListeners, which are
// BasicListUI$Handler and BasicComboBoxUI$Handler.
AbstractListModel
listModel
=
(
AbstractListModel
)
model
;
String
listenerClass1
=
"javax.swing.plaf.basic.BasicListUI$Handler"
;
String
listenerClass2
=
"javax.swing.plaf.basic.BasicComboBoxUI$Handler"
;
for
(
ListDataListener
listener
:
listModel
.
getListDataListeners
())
{
if
(
listenerClass1
.
equals
(
listener
.
getClass
().
getName
())
||
listenerClass2
.
equals
(
listener
.
getClass
().
getName
()))
{
listModel
.
removeListDataListener
(
listener
);
}
}
}
else
if
(
model
instanceof
AbstractDocument
)
{
// case of JPasswordField, JTextField and JTextArea
// All have 2 stale DocumentListeners.
String
listenerClass1
=
"javax.swing.plaf.basic.BasicTextUI$UpdateHandler"
;
String
listenerClass2
=
"javax.swing.text.DefaultCaret$Handler"
;
AbstractDocument
docModel
=
(
AbstractDocument
)
model
;
for
(
DocumentListener
listener
:
docModel
.
getDocumentListeners
())
{
if
(
listenerClass1
.
equals
(
listener
.
getClass
().
getName
())
||
listenerClass2
.
equals
(
listener
.
getClass
().
getName
()))
{
docModel
.
removeDocumentListener
(
listener
);
}
}
}
}
/**
* Determines the maximum span for this view along an
...
...
@@ -347,7 +408,7 @@ public class FormView extends ComponentView implements ActionListener {
/**
* Responsible for process
e
ing the ActionEvent.
* Responsible for processing the ActionEvent.
* If the element associated with the FormView,
* has a type of "submit", "reset", "text" or "password"
* then the action is processed. In the case of a "submit"
...
...
test/javax/swing/text/html/7189299/bug7189299.java
0 → 100644
浏览文件 @
5bd32ca4
/*
* Copyright (c) 2013 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.
*/
/*
* Portions Copyright (c) 2013 IBM Corporation
*/
import
java.awt.BorderLayout
;
import
java.awt.Toolkit
;
import
java.awt.event.ActionListener
;
import
javax.swing.DefaultButtonModel
;
import
javax.swing.JEditorPane
;
import
javax.swing.JFrame
;
import
javax.swing.SwingUtilities
;
import
javax.swing.text.StyleConstants
;
import
javax.swing.text.StyleContext
;
import
javax.swing.text.html.HTMLEditorKit
;
import
sun.awt.SunToolkit
;
/*
* @test
* @bug 8008289
* @summary Shared ButtonModel instance should deregister previous listeners.
* @author Frank Ding
*/
public
class
bug7189299
{
private
static
JEditorPane
html
;
private
static
JFrame
frame
;
private
static
void
setup
()
{
/**
* Note the input type is not restricted to "submit". Types "image",
* "checkbox", "radio" have the same problem.
*/
html
=
new
JEditorPane
(
"text/html"
,
"<html><body><form action=\"http://localhost.cgi\">"
+
"<input type=submit name=submit value=\"submit\"/>"
+
"</form></body></html>"
);
frame
=
new
JFrame
();
frame
.
setLayout
(
new
BorderLayout
());
frame
.
add
(
html
,
BorderLayout
.
CENTER
);
frame
.
setSize
(
200
,
100
);
frame
.
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
frame
.
setVisible
(
true
);
}
private
static
void
doTest
()
{
/*
* Calling updateComponentTreeUI creates a new FormView instance with
* its own associated JButton instance. The same DefaultButtonModel
* instance is used for both FormView's.
*
* The action listeners associated with (the JButton for) the first
* FormView should be unregistered from this common DefaultButtonModel,
* such that only those for the new FormView remain.
*/
SwingUtilities
.
updateComponentTreeUI
(
html
);
}
private
static
void
verifySingleDefaultButtonModelListener
()
{
HTMLEditorKit
htmlEditorKit
=
(
HTMLEditorKit
)
html
.
getEditorKit
();
StyleContext
.
NamedStyle
style
=
((
StyleContext
.
NamedStyle
)
htmlEditorKit
.
getInputAttributes
());
DefaultButtonModel
model
=
((
DefaultButtonModel
)
style
.
getAttribute
(
StyleConstants
.
ModelAttribute
));
ActionListener
[]
listeners
=
model
.
getActionListeners
();
int
actionListenerNum
=
listeners
.
length
;
if
(
actionListenerNum
!=
1
)
{
throw
new
RuntimeException
(
"Expected single ActionListener object registered with "
+
"DefaultButtonModel; found "
+
actionListenerNum
+
" listeners registered."
);
}
int
changeListenerNum
=
model
.
getChangeListeners
().
length
;
if
(
changeListenerNum
!=
1
)
{
throw
new
RuntimeException
(
"Expected at most one ChangeListener object registered "
+
"with DefaultButtonModel; found "
+
changeListenerNum
+
" listeners registered."
);
}
int
itemListenerNum
=
model
.
getItemListeners
().
length
;
if
(
itemListenerNum
!=
1
)
{
throw
new
RuntimeException
(
"Expected at most one ItemListener object registered "
+
"with DefaultButtonModel; found "
+
itemListenerNum
+
" listeners registered."
);
}
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
final
SunToolkit
toolkit
=
((
SunToolkit
)
Toolkit
.
getDefaultToolkit
());
SwingUtilities
.
invokeAndWait
(
new
Runnable
()
{
@Override
public
void
run
()
{
setup
();
}
});
toolkit
.
realSync
();
SwingUtilities
.
invokeAndWait
(
new
Runnable
()
{
@Override
public
void
run
()
{
try
{
verifySingleDefaultButtonModelListener
();
doTest
();
verifySingleDefaultButtonModelListener
();
}
finally
{
frame
.
dispose
();
}
}
});
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录