Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
a1ad8d18
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看板
提交
a1ad8d18
编写于
5月 25, 2010
作者:
A
alexp
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6884066: JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
Reviewed-by: rupashka
上级
5e15d645
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
179 addition
and
29 deletion
+179
-29
src/share/classes/com/sun/java/swing/plaf/windows/WindowsTableHeaderUI.java
...com/sun/java/swing/plaf/windows/WindowsTableHeaderUI.java
+5
-9
src/share/classes/javax/swing/JTable.java
src/share/classes/javax/swing/JTable.java
+4
-14
src/share/classes/javax/swing/plaf/basic/BasicTableHeaderUI.java
...re/classes/javax/swing/plaf/basic/BasicTableHeaderUI.java
+29
-6
src/share/classes/sun/swing/SwingUtilities2.java
src/share/classes/sun/swing/SwingUtilities2.java
+52
-0
test/javax/swing/JTableHeader/6884066/bug6884066.java
test/javax/swing/JTableHeader/6884066/bug6884066.java
+89
-0
未找到文件。
src/share/classes/com/sun/java/swing/plaf/windows/WindowsTableHeaderUI.java
浏览文件 @
a1ad8d18
...
...
@@ -35,6 +35,7 @@ import javax.swing.table.*;
import
static
com
.
sun
.
java
.
swing
.
plaf
.
windows
.
TMSchema
.*;
import
static
com
.
sun
.
java
.
swing
.
plaf
.
windows
.
XPStyle
.*;
import
sun.swing.table.*
;
import
sun.swing.SwingUtilities2
;
public
class
WindowsTableHeaderUI
extends
BasicTableHeaderUI
{
...
...
@@ -163,18 +164,13 @@ public class WindowsTableHeaderUI extends BasicTableHeaderUI {
return
this
;
}
private
int
viewIndexForColumn
(
TableColumn
aColumn
)
{
if
(
aColumn
!=
null
)
{
return
header
.
getTable
().
convertColumnIndexToView
(
aColumn
.
getModelIndex
());
}
return
-
1
;
}
public
void
paint
(
Graphics
g
)
{
Dimension
size
=
getSize
();
State
state
=
State
.
NORMAL
;
if
(
column
==
viewIndexForColumn
(
header
.
getDraggedColumn
()))
{
TableColumn
draggedColumn
=
header
.
getDraggedColumn
();
if
(
draggedColumn
!=
null
&&
column
==
SwingUtilities2
.
convertColumnIndexToView
(
header
.
getColumnModel
(),
draggedColumn
.
getModelIndex
()))
{
state
=
State
.
PRESSED
;
}
else
if
(
isSelected
||
hasFocus
||
hasRollover
)
{
state
=
State
.
HOT
;
...
...
src/share/classes/javax/swing/JTable.java
浏览文件 @
a1ad8d18
...
...
@@ -2583,10 +2583,8 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
* @see #convertColumnIndexToView
*/
public
int
convertColumnIndexToModel
(
int
viewColumnIndex
)
{
if
(
viewColumnIndex
<
0
)
{
return
viewColumnIndex
;
}
return
getColumnModel
().
getColumn
(
viewColumnIndex
).
getModelIndex
();
return
SwingUtilities2
.
convertColumnIndexToModel
(
getColumnModel
(),
viewColumnIndex
);
}
/**
...
...
@@ -2603,16 +2601,8 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
* @see #convertColumnIndexToModel
*/
public
int
convertColumnIndexToView
(
int
modelColumnIndex
)
{
if
(
modelColumnIndex
<
0
)
{
return
modelColumnIndex
;
}
TableColumnModel
cm
=
getColumnModel
();
for
(
int
column
=
0
;
column
<
getColumnCount
();
column
++)
{
if
(
cm
.
getColumn
(
column
).
getModelIndex
()
==
modelColumnIndex
)
{
return
column
;
}
}
return
-
1
;
return
SwingUtilities2
.
convertColumnIndexToView
(
getColumnModel
(),
modelColumnIndex
);
}
/**
...
...
src/share/classes/javax/swing/plaf/basic/BasicTableHeaderUI.java
浏览文件 @
a1ad8d18
...
...
@@ -98,15 +98,18 @@ public class BasicTableHeaderUI extends TableHeaderUI {
private
Cursor
otherCursor
=
resizeCursor
;
public
void
mouseClicked
(
MouseEvent
e
)
{
if
(
SwingUtilities2
.
shouldIgnore
(
e
,
header
))
{
return
;
}
if
(
e
.
getClickCount
()
%
2
==
1
&&
SwingUtilities
.
isLeftMouseButton
(
e
)){
SwingUtilities
.
isLeftMouseButton
(
e
))
{
JTable
table
=
header
.
getTable
();
RowSorter
sorter
;
if
(
table
!=
null
&&
(
sorter
=
table
.
getRowSorter
())
!=
null
)
{
int
columnIndex
=
header
.
columnAtPoint
(
e
.
getPoint
());
if
(
columnIndex
!=
-
1
)
{
columnIndex
=
table
.
convertColumnIndexToModel
(
columnIndex
);
columnIndex
);
sorter
.
toggleSortOrder
(
columnIndex
);
}
}
...
...
@@ -140,6 +143,9 @@ public class BasicTableHeaderUI extends TableHeaderUI {
}
public
void
mousePressed
(
MouseEvent
e
)
{
if
(
SwingUtilities2
.
shouldIgnore
(
e
,
header
))
{
return
;
}
header
.
setDraggedColumn
(
null
);
header
.
setResizingColumn
(
null
);
header
.
setDraggedDistance
(
0
);
...
...
@@ -182,6 +188,9 @@ public class BasicTableHeaderUI extends TableHeaderUI {
}
public
void
mouseMoved
(
MouseEvent
e
)
{
if
(
SwingUtilities2
.
shouldIgnore
(
e
,
header
))
{
return
;
}
if
(
canResize
(
getResizingColumn
(
e
.
getPoint
()),
header
)
!=
(
header
.
getCursor
()
==
resizeCursor
))
{
swapCursor
();
...
...
@@ -190,6 +199,9 @@ public class BasicTableHeaderUI extends TableHeaderUI {
}
public
void
mouseDragged
(
MouseEvent
e
)
{
if
(
SwingUtilities2
.
shouldIgnore
(
e
,
header
))
{
return
;
}
int
mouseX
=
e
.
getX
();
TableColumn
resizingColumn
=
header
.
getResizingColumn
();
...
...
@@ -217,21 +229,23 @@ public class BasicTableHeaderUI extends TableHeaderUI {
if
(
0
<=
newColumnIndex
&&
newColumnIndex
<
cm
.
getColumnCount
())
{
int
width
=
cm
.
getColumn
(
newColumnIndex
).
getWidth
();
if
(
Math
.
abs
(
draggedDistance
)
>
(
width
/
2
))
{
JTable
table
=
header
.
getTable
();
mouseXOffset
=
mouseXOffset
+
direction
*
width
;
header
.
setDraggedDistance
(
draggedDistance
-
direction
*
width
);
//Cache the selected column.
int
selectedIndex
=
table
.
convertColumnIndexToModel
(
getSelectedColumnIndex
());
int
selectedIndex
=
SwingUtilities2
.
convertColumnIndexToModel
(
header
.
getColumnModel
(),
getSelectedColumnIndex
());
//Now do the move.
cm
.
moveColumn
(
columnIndex
,
newColumnIndex
);
//Update the selected index.
selectColumn
(
table
.
convertColumnIndexToView
(
selectedIndex
),
SwingUtilities2
.
convertColumnIndexToView
(
header
.
getColumnModel
(),
selectedIndex
),
false
);
return
;
...
...
@@ -244,6 +258,9 @@ public class BasicTableHeaderUI extends TableHeaderUI {
}
public
void
mouseReleased
(
MouseEvent
e
)
{
if
(
SwingUtilities2
.
shouldIgnore
(
e
,
header
))
{
return
;
}
setDraggedDistance
(
0
,
viewIndexForColumn
(
header
.
getDraggedColumn
()));
header
.
setResizingColumn
(
null
);
...
...
@@ -253,10 +270,16 @@ public class BasicTableHeaderUI extends TableHeaderUI {
}
public
void
mouseEntered
(
MouseEvent
e
)
{
if
(
SwingUtilities2
.
shouldIgnore
(
e
,
header
))
{
return
;
}
updateRolloverColumn
(
e
);
}
public
void
mouseExited
(
MouseEvent
e
)
{
if
(
SwingUtilities2
.
shouldIgnore
(
e
,
header
))
{
return
;
}
int
oldRolloverColumn
=
rolloverColumn
;
rolloverColumn
=
-
1
;
rolloverColumnUpdated
(
oldRolloverColumn
,
rolloverColumn
);
...
...
src/share/classes/sun/swing/SwingUtilities2.java
浏览文件 @
a1ad8d18
...
...
@@ -44,6 +44,8 @@ import javax.swing.text.JTextComponent;
import
javax.swing.text.DefaultHighlighter
;
import
javax.swing.text.DefaultCaret
;
import
javax.swing.table.TableCellRenderer
;
import
javax.swing.table.TableColumnModel
;
import
sun.swing.PrintColorUIResource
;
import
sun.swing.ImageIconUIResource
;
import
sun.print.ProxyPrintGraphics
;
...
...
@@ -1807,4 +1809,54 @@ public class SwingUtilities2 {
boolean
three
)
{
return
liesIn
(
rect
,
p
,
false
,
false
,
three
);
}
/**
* Maps the index of the column in the view at
* {@code viewColumnIndex} to the index of the column
* in the table model. Returns the index of the corresponding
* column in the model. If {@code viewColumnIndex}
* is less than zero, returns {@code viewColumnIndex}.
*
* @param cm the table model
* @param viewColumnIndex the index of the column in the view
* @return the index of the corresponding column in the model
*
* @see JTable#convertColumnIndexToModel(int)
* @see javax.swing.plaf.basic.BasicTableHeaderUI
*/
public
static
int
convertColumnIndexToModel
(
TableColumnModel
cm
,
int
viewColumnIndex
)
{
if
(
viewColumnIndex
<
0
)
{
return
viewColumnIndex
;
}
return
cm
.
getColumn
(
viewColumnIndex
).
getModelIndex
();
}
/**
* Maps the index of the column in the {@code cm} at
* {@code modelColumnIndex} to the index of the column
* in the view. Returns the index of the
* corresponding column in the view; returns {@code -1} if this column
* is not being displayed. If {@code modelColumnIndex} is less than zero,
* returns {@code modelColumnIndex}.
*
* @param cm the table model
* @param modelColumnIndex the index of the column in the model
* @return the index of the corresponding column in the view
*
* @see JTable#convertColumnIndexToView(int)
* @see javax.swing.plaf.basic.BasicTableHeaderUI
*/
public
static
int
convertColumnIndexToView
(
TableColumnModel
cm
,
int
modelColumnIndex
)
{
if
(
modelColumnIndex
<
0
)
{
return
modelColumnIndex
;
}
for
(
int
column
=
0
;
column
<
cm
.
getColumnCount
();
column
++)
{
if
(
cm
.
getColumn
(
column
).
getModelIndex
()
==
modelColumnIndex
)
{
return
column
;
}
}
return
-
1
;
}
}
test/javax/swing/JTableHeader/6884066/bug6884066.java
0 → 100644
浏览文件 @
a1ad8d18
/*
* Copyright 2010 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/* @test
@bug 6884066
@summary JTableHeader listens mouse in disabled state and doesn't work when not attached to a table
@author Alexander Potochkin
@run main bug6884066
*/
import
sun.awt.SunToolkit
;
import
javax.swing.*
;
import
javax.swing.table.JTableHeader
;
import
javax.swing.table.TableColumnModel
;
import
javax.swing.table.TableColumn
;
import
java.awt.*
;
import
java.awt.event.InputEvent
;
import
com.sun.java.swing.plaf.windows.WindowsLookAndFeel
;
public
class
bug6884066
{
private
static
JTableHeader
header
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
UIManager
.
setLookAndFeel
(
UIManager
.
getSystemLookAndFeelClassName
());
SunToolkit
toolkit
=
(
SunToolkit
)
Toolkit
.
getDefaultToolkit
();
Robot
robot
=
new
Robot
();
robot
.
setAutoDelay
(
20
);
SwingUtilities
.
invokeAndWait
(
new
Runnable
()
{
public
void
run
()
{
// just to quickly grab a column model
JTable
table
=
new
JTable
(
10
,
5
);
header
=
new
JTableHeader
(
table
.
getColumnModel
());
checkColumn
(
0
,
"A"
);
JFrame
frame
=
new
JFrame
(
"standalone header"
);
frame
.
add
(
header
);
frame
.
pack
();
frame
.
setVisible
(
true
);
frame
.
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
}
});
toolkit
.
realSync
();
Point
point
=
header
.
getLocationOnScreen
();
robot
.
mouseMove
(
point
.
x
+
3
,
point
.
y
+
3
);
robot
.
mousePress
(
InputEvent
.
BUTTON1_MASK
);
for
(
int
i
=
0
;
i
<
header
.
getWidth
()
-
3
;
i
++)
{
robot
.
mouseMove
(
point
.
x
+
i
,
point
.
y
+
3
);
}
robot
.
mouseRelease
(
InputEvent
.
BUTTON1_MASK
);
SwingUtilities
.
invokeAndWait
(
new
Runnable
()
{
public
void
run
()
{
TableColumnModel
model
=
header
.
getColumnModel
();
checkColumn
(
model
.
getColumnCount
()
-
1
,
"A"
);
}
});
}
private
static
void
checkColumn
(
int
index
,
String
str
)
{
TableColumnModel
model
=
header
.
getColumnModel
();
Object
value
=
model
.
getColumn
(
index
).
getHeaderValue
();
if
(!
str
.
equals
(
value
))
{
throw
new
RuntimeException
(
"Unexpected header's value; "
+
"index = "
+
index
+
" value = "
+
value
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录