Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
30c6e2bd
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看板
提交
30c6e2bd
编写于
11月 24, 2009
作者:
D
denis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
Reviewed-by: uta, dav
上级
cb7fbfa4
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
577 addition
and
8 deletion
+577
-8
src/share/classes/sun/awt/datatransfer/DataTransferer.java
src/share/classes/sun/awt/datatransfer/DataTransferer.java
+19
-6
src/windows/native/sun/windows/awt_DnDDS.cpp
src/windows/native/sun/windows/awt_DnDDS.cpp
+2
-2
test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/AbsoluteComponentCenterCalculator.java
...codeBetweenJVMTest/AbsoluteComponentCenterCalculator.java
+34
-0
test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/DragUnicodeBetweenJVMTest.html
.../DragUnicodeBetweenJVMTest/DragUnicodeBetweenJVMTest.html
+25
-0
test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/DragUnicodeBetweenJVMTest.java
.../DragUnicodeBetweenJVMTest/DragUnicodeBetweenJVMTest.java
+193
-0
test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/FileListTransferable.java
...nsfer/DragUnicodeBetweenJVMTest/FileListTransferable.java
+68
-0
test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/InterprocessMessages.java
...nsfer/DragUnicodeBetweenJVMTest/InterprocessMessages.java
+28
-0
test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/NextFramePositionCalculator.java
...ragUnicodeBetweenJVMTest/NextFramePositionCalculator.java
+43
-0
test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/SourcePanel.java
...t/datatransfer/DragUnicodeBetweenJVMTest/SourcePanel.java
+50
-0
test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/TargetPanel.java
...t/datatransfer/DragUnicodeBetweenJVMTest/TargetPanel.java
+115
-0
未找到文件。
src/share/classes/sun/awt/datatransfer/DataTransferer.java
浏览文件 @
30c6e2bd
...
...
@@ -203,6 +203,8 @@ public abstract class DataTransferer {
private
static
final
Map
nativeEOLNs
=
Collections
.
synchronizedMap
(
new
HashMap
());
private
static
final
byte
[]
UNICODE_NULL_TERMINATOR
=
new
byte
[]
{
0
,
0
};
/**
* The number of terminating NUL bytes for the Set of textNatives.
*/
...
...
@@ -1299,7 +1301,7 @@ search:
}
final
List
list
=
(
List
)
obj
;
final
ArrayList
fileList
=
new
ArrayList
();
final
ArrayList
<
String
>
fileList
=
new
ArrayList
<
String
>
();
final
ProtectionDomain
userProtectionDomain
=
getUserProtectionDomain
(
contents
);
...
...
@@ -1331,13 +1333,24 @@ search:
throw
new
IOException
(
pae
.
getMessage
());
}
for
(
int
i
=
0
;
i
<
fileList
.
size
();
i
++)
{
byte
[]
bytes
=
((
String
)
fileList
.
get
(
i
)).
getBytes
();
if
(
i
!=
0
)
bos
.
write
(
0
);
bos
.
write
(
bytes
,
0
,
bytes
.
length
);
if
(
fileList
.
isEmpty
())
{
//store empty unicode string (null terminator)
bos
.
write
(
UNICODE_NULL_TERMINATOR
);
}
else
{
for
(
int
i
=
0
;
i
<
fileList
.
size
();
i
++)
{
byte
[]
bytes
=
fileList
.
get
(
i
).
getBytes
(
getDefaultUnicodeEncoding
());
//store unicode string with null terminator
bos
.
write
(
bytes
,
0
,
bytes
.
length
);
bos
.
write
(
UNICODE_NULL_TERMINATOR
);
}
}
// According to MSDN the byte array have to be double NULL-terminated.
// The array contains Unicode characters, so each NULL-terminator is
// a pair of bytes
bos
.
write
(
UNICODE_NULL_TERMINATOR
);
// Source data is an InputStream. For arbitrary flavors, just grab the
// bytes and dump them into a byte array. For text flavors, decode back
// to a String and recur to reencode according to the requested format.
...
...
src/windows/native/sun/windows/awt_DnDDS.cpp
浏览文件 @
30c6e2bd
...
...
@@ -648,7 +648,7 @@ HRESULT __stdcall AwtDragSource::GetData(FORMATETC __RPC_FAR *pFormatEtc,
dropfiles
->
pt
.
x
=
m_dropPoint
.
x
;
dropfiles
->
pt
.
y
=
m_dropPoint
.
y
;
dropfiles
->
fNC
=
m_fNC
;
dropfiles
->
fWide
=
FALS
E
;
// good guess!
dropfiles
->
fWide
=
TRU
E
;
// good guess!
dataout
+=
sizeof
(
DROPFILES
);
}
...
...
@@ -815,7 +815,7 @@ HRESULT __stdcall AwtDragSource::GetDataHere(FORMATETC __RPC_FAR *pFormatEtc,
dropfiles
->
pt
.
x
=
m_dropPoint
.
x
;
dropfiles
->
pt
.
y
=
m_dropPoint
.
y
;
dropfiles
->
fNC
=
m_fNC
;
dropfiles
->
fWide
=
FALS
E
;
// good guess!
dropfiles
->
fWide
=
TRU
E
;
// good guess!
dataout
+=
sizeof
(
DROPFILES
);
}
...
...
test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/AbsoluteComponentCenterCalculator.java
0 → 100644
浏览文件 @
30c6e2bd
/*
* Copyright 2009 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.
*/
import
java.awt.*
;
class
AbsoluteComponentCenterCalculator
{
private
AbsoluteComponentCenterCalculator
()
{}
public
static
int
calculateXCenterCoordinate
(
Component
component
)
{
return
(
int
)
component
.
getLocationOnScreen
().
getX
()+(
component
.
getWidth
()/
2
);
}
public
static
int
calculateYCenterCoordinate
(
Component
component
)
{
return
(
int
)
component
.
getLocationOnScreen
().
getY
()+(
component
.
getHeight
()/
2
);
}
}
test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/DragUnicodeBetweenJVMTest.html
0 → 100644
浏览文件 @
30c6e2bd
<html>
<!--
@test
@bug 5098433
@summary REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
@author Denis Fokin: area=dnd
@library ../../regtesthelpers
@library ../../regtesthelpers/process
@build Util
@build ProcessResults ProcessCommunicator
@run applet/othervm DragUnicodeBetweenJVMTest.html
-->
<head>
<title>
REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
</title>
</head>
<body>
<h1>
DragUnicodeBetweenJVMTest
<br>
Bug ID: 5098433
</h1>
<p>
This is an AUTOMATIC test, simply wait for completion
</p>
<APPLET
CODE=
"DragUnicodeBetweenJVMTest.class"
WIDTH=
200
HEIGHT=
200
></APPLET>
</body>
</html>
test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/DragUnicodeBetweenJVMTest.java
0 → 100644
浏览文件 @
30c6e2bd
/*
* Copyright 2009 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 5098433
@summary REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
@author Denis Fokin: area=dnd
@library ../../regtesthelpers
@library ../../regtesthelpers/process
@build Util
@build ProcessResults ProcessCommunicator
@run applet/othervm DragUnicodeBetweenJVMTest.html
*/
/**
* DragUnicodeBetweenJVMTest.java
*
* summary: The test drags a list of files (DataFlavor.javaFileListFlavor) from one jvm to another.
* The files have Unicode names. The list on target side must be equal to
* the list on the source side.
*/
import
java.awt.*
;
import
java.awt.event.*
;
import
java.applet.Applet
;
import
test.java.awt.regtesthelpers.process.ProcessCommunicator
;
import
test.java.awt.regtesthelpers.process.ProcessResults
;
import
test.java.awt.regtesthelpers.Util
;
import
static
java
.
lang
.
Thread
.
sleep
;
public
class
DragUnicodeBetweenJVMTest
extends
Applet
{
public
void
init
()
{
setLayout
(
new
BorderLayout
());
}
//End init()
public
void
start
()
{
String
toolkit
=
Toolkit
.
getDefaultToolkit
().
getClass
().
getName
();
if
(!
toolkit
.
equals
(
"sun.awt.windows.WToolkit"
)){
System
.
out
.
println
(
"This test is for Windows only. Passed."
);
return
;
}
else
{
System
.
out
.
println
(
"Toolkit = "
+
toolkit
);
}
final
Frame
sourceFrame
=
new
Frame
(
"Source frame"
);
final
SourcePanel
sourcePanel
=
new
SourcePanel
();
sourceFrame
.
add
(
sourcePanel
);
sourceFrame
.
pack
();
sourceFrame
.
addWindowListener
(
new
WindowAdapter
()
{
@Override
public
void
windowClosing
(
WindowEvent
e
)
{
sourceFrame
.
dispose
();
}
});
sourceFrame
.
setVisible
(
true
);
Util
.
waitForIdle
(
null
);
NextFramePositionCalculator
positionCalculator
=
new
NextFramePositionCalculator
(
sourceFrame
);
String
[]
args
=
new
String
[]
{
String
.
valueOf
(
positionCalculator
.
getNextLocationX
()),
String
.
valueOf
(
positionCalculator
.
getNextLocationY
()),
String
.
valueOf
(
AbsoluteComponentCenterCalculator
.
calculateXCenterCoordinate
(
sourcePanel
)),
String
.
valueOf
(
AbsoluteComponentCenterCalculator
.
calculateYCenterCoordinate
(
sourcePanel
)),
};
ProcessResults
processResults
=
// ProcessCommunicator.executeChildProcess(this.getClass()," -cp \"C:\\Documents and Settings\\df153228\\IdeaProjects\\UnicodeTestDebug\\out\\production\\UnicodeTestDebug\" -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 ", args);
ProcessCommunicator
.
executeChildProcess
(
this
.
getClass
(),
args
);
verifyTestResults
(
processResults
);
}
// start()
private
static
void
verifyTestResults
(
ProcessResults
processResults
)
{
if
(
InterprocessMessages
.
FILES_ON_TARGET_ARE_CORRUPTED
==
processResults
.
getExitValue
())
{
processResults
.
printProcessErrorOutput
(
System
.
err
);
throw
new
RuntimeException
(
"TEST IS FAILED: Target has recieved"
+
" broken file list."
);
}
processResults
.
verifyStdErr
(
System
.
err
);
processResults
.
verifyProcessExitValue
(
System
.
err
);
processResults
.
printProcessStandartOutput
(
System
.
out
);
}
//We cannot make an instance of the applet without the default constructor
public
DragUnicodeBetweenJVMTest
()
{
super
();
}
//We need in this constructor to pass frame position between JVMs
public
DragUnicodeBetweenJVMTest
(
Point
targetFrameLocation
,
Point
dragSourcePoint
)
throws
InterruptedException
{
final
Frame
targetFrame
=
new
Frame
(
"Target frame"
);
final
TargetPanel
targetPanel
=
new
TargetPanel
(
targetFrame
);
targetFrame
.
add
(
targetPanel
);
targetFrame
.
addWindowListener
(
new
WindowAdapter
()
{
@Override
public
void
windowClosing
(
WindowEvent
e
)
{
targetFrame
.
dispose
();
}
});
targetFrame
.
setLocation
(
targetFrameLocation
);
targetFrame
.
pack
();
targetFrame
.
setVisible
(
true
);
doTest
(
dragSourcePoint
,
targetPanel
);
}
private
void
doTest
(
Point
dragSourcePoint
,
TargetPanel
targetPanel
)
{
Util
.
waitForIdle
(
null
);
final
Robot
robot
=
Util
.
createRobot
();
robot
.
mouseMove
((
int
)
dragSourcePoint
.
getX
(),(
int
)
dragSourcePoint
.
getY
());
try
{
sleep
(
100
);
robot
.
mousePress
(
InputEvent
.
BUTTON1_MASK
);
sleep
(
100
);
robot
.
mouseRelease
(
InputEvent
.
BUTTON1_MASK
);
sleep
(
100
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
Util
.
drag
(
robot
,
dragSourcePoint
,
new
Point
(
AbsoluteComponentCenterCalculator
.
calculateXCenterCoordinate
(
targetPanel
),
AbsoluteComponentCenterCalculator
.
calculateYCenterCoordinate
(
targetPanel
)),
InputEvent
.
BUTTON1_MASK
);
}
enum
InterprocessArguments
{
TARGET_FRAME_X_POSITION_ARGUMENT
,
TARGET_FRAME_Y_POSITION_ARGUMENT
,
DRAG_SOURCE_POINT_X_ARGUMENT
,
DRAG_SOURCE_POINT_Y_ARGUMENT
;
int
extract
(
String
[]
args
)
{
return
Integer
.
parseInt
(
args
[
this
.
ordinal
()]);
}
}
public
static
void
main
(
String
[]
args
)
{
Point
dragSourcePoint
=
new
Point
(
InterprocessArguments
.
DRAG_SOURCE_POINT_X_ARGUMENT
.
extract
(
args
),
InterprocessArguments
.
DRAG_SOURCE_POINT_Y_ARGUMENT
.
extract
(
args
));
Point
targetFrameLocation
=
new
Point
(
InterprocessArguments
.
TARGET_FRAME_X_POSITION_ARGUMENT
.
extract
(
args
),
InterprocessArguments
.
TARGET_FRAME_Y_POSITION_ARGUMENT
.
extract
(
args
));
try
{
new
DragUnicodeBetweenJVMTest
(
targetFrameLocation
,
dragSourcePoint
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
}
test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/FileListTransferable.java
0 → 100644
浏览文件 @
30c6e2bd
/*
* Copyright 2009 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.
*/
import
java.awt.datatransfer.Transferable
;
import
java.awt.datatransfer.DataFlavor
;
import
java.awt.datatransfer.UnsupportedFlavorException
;
import
java.io.IOException
;
import
java.io.File
;
import
java.util.Arrays
;
import
java.util.List
;
class
FileListTransferable
implements
Transferable
{
public
static
File
[]
files
=
new
File
[]
{
new
File
(
"\u042f\u0020\u0441\u0440\u0430\u0437\u0443\u0020\u0441\u043c\u0430\u0437\u0430\u043b"
+
"\u0020\u043a\u0430\u0440\u0442\u0443\u0020\u0431\u0443\u0434\u043d\u044f"
),
new
File
(
"\u043f\u043b\u0435\u0441\u043d\u0443\u0432\u0448\u0438\u0020\u043a\u0440\u0430\u0441"
+
"\u043a\u0443\u0020\u0438\u0437\u0020\u0441\u0442\u0430\u043a\u0430\u043d\u0430"
),
new
File
(
"\u044f\u0020\u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0020\u043d\u0430\u0020\u0431"
+
"\u043b\u044e\u0434\u0435\u0020\u0441\u0442\u0443\u0434\u043d\u044f"
),
new
File
(
"\u043a\u043e\u0441\u044b\u0435\u0020\u0441\u043a\u0443\u043b\u044b\u0020\u043e\u043a"
+
"\u0435\u0430\u043d\u0430"
),
new
File
(
"\u041d\u0430\u0020\u0447\u0435\u0448\u0443\u0435\u0020\u0436\u0435\u0441\u0442\u044f"
+
"\u043d\u043e\u0439\u0020\u0440\u044b\u0431\u044b"
),
new
File
(
"\u043f\u0440\u043e\u0447\u0435\u043b\u0020\u044f\u0020\u0437\u043e\u0432\u044b\u0020"
+
"\u043d\u043e\u0432\u044b\u0445\u0020\u0433\u0443\u0431"
),
new
File
(
"\u0410\u0020\u0432\u044b"
),
new
File
(
"\u043d\u043e\u043a\u0442\u044e\u0440\u043d\u0020\u0441\u044b\u0433\u0440\u0430\u0442"
+
"\u044c"
),
new
File
(
"\u043c\u043e\u0433\u043b\u0438\u0020\u0431\u044b"
),
new
File
(
"\u043d\u0430\u0020\u0444\u043b\u0435\u0439\u0442\u0435\u0020\u0432\u043e\u0434\u043e"
+
"\u0441\u0442\u043e\u0447\u043d\u044b\u0445\u0020\u0442\u0440\u0443\u0431"
),
};
public
DataFlavor
[]
getTransferDataFlavors
()
{
return
new
DataFlavor
[]
{
DataFlavor
.
javaFileListFlavor
};
}
public
boolean
isDataFlavorSupported
(
DataFlavor
flavor
)
{
return
flavor
.
equals
(
DataFlavor
.
javaFileListFlavor
)
;
}
public
Object
getTransferData
(
DataFlavor
flavor
)
throws
UnsupportedFlavorException
,
IOException
{
List
<
File
>
list
=
Arrays
.
asList
(
files
);
return
list
;
}
}
test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/InterprocessMessages.java
0 → 100644
浏览文件 @
30c6e2bd
/*
* Copyright 2009 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.
*/
interface
InterprocessMessages
{
final
static
int
EXECUTION_IS_SUCCESSFULL
=
0
;
final
static
int
FILES_ON_TARGET_ARE_CORRUPTED
=
212
;
}
test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/NextFramePositionCalculator.java
0 → 100644
浏览文件 @
30c6e2bd
/*
* Copyright 2009 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.
*/
import
java.awt.*
;
class
NextFramePositionCalculator
{
private
final
Frame
currentFrame
;
public
NextFramePositionCalculator
(
Frame
currentFrame
)
{
this
.
currentFrame
=
currentFrame
;
}
public
int
getNextLocationX
()
{
return
currentFrame
.
getX
()+
currentFrame
.
getWidth
();
}
public
int
getNextLocationY
()
{
return
currentFrame
.
getY
();
}
}
test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/SourcePanel.java
0 → 100644
浏览文件 @
30c6e2bd
/*
* Copyright 2009 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.
*/
import
java.awt.dnd.DragSource
;
import
java.awt.dnd.DnDConstants
;
import
java.awt.dnd.DragGestureEvent
;
import
java.awt.dnd.DragGestureListener
;
import
java.awt.*
;
public
class
SourcePanel
extends
Panel
{
private
final
MyDragGestureListener
dragGestureListener
=
new
MyDragGestureListener
();
public
SourcePanel
()
{
setPreferredSize
(
new
Dimension
(
200
,
200
));
DragSource
defaultDragSource
=
DragSource
.
getDefaultDragSource
();
defaultDragSource
.
createDefaultDragGestureRecognizer
(
this
,
DnDConstants
.
ACTION_COPY_OR_MOVE
,
dragGestureListener
);
setBackground
(
Color
.
RED
);
}
private
class
MyDragGestureListener
implements
DragGestureListener
{
public
void
dragGestureRecognized
(
DragGestureEvent
dge
)
{
dge
.
startDrag
(
null
,
new
FileListTransferable
());
}
}
}
test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/TargetPanel.java
0 → 100644
浏览文件 @
30c6e2bd
/*
* Copyright 2009 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.
*/
import
java.awt.dnd.*
;
import
java.awt.*
;
import
java.awt.datatransfer.DataFlavor
;
import
java.awt.datatransfer.UnsupportedFlavorException
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Iterator
;
import
java.util.Arrays
;
public
class
TargetPanel
extends
Panel
implements
DropTargetListener
{
private
java
.
util
.
List
<
File
>
content
=
new
ArrayList
<
File
>();
//private final CustomDropTargetListener dropTargetListener = new CustomDropTargetListener();
private
Frame
frame
;
public
TargetPanel
(
Frame
frame
)
{
this
.
frame
=
frame
;
setBackground
(
Color
.
DARK_GRAY
);
setPreferredSize
(
new
Dimension
(
200
,
200
));
setDropTarget
(
new
DropTarget
(
this
,
this
));
}
public
void
dragEnter
(
DropTargetDragEvent
dtde
)
{
if
(
dtde
.
isDataFlavorSupported
(
DataFlavor
.
javaFileListFlavor
))
{
dtde
.
acceptDrag
(
DnDConstants
.
ACTION_COPY_OR_MOVE
);
}
}
public
void
dragOver
(
DropTargetDragEvent
dtde
)
{
if
(
dtde
.
isDataFlavorSupported
(
DataFlavor
.
javaFileListFlavor
))
{
dtde
.
acceptDrag
(
DnDConstants
.
ACTION_COPY_OR_MOVE
);
}
}
public
void
dropActionChanged
(
DropTargetDragEvent
dtde
)
{
if
(
dtde
.
isDataFlavorSupported
(
DataFlavor
.
javaFileListFlavor
))
{
dtde
.
acceptDrag
(
DnDConstants
.
ACTION_COPY_OR_MOVE
);
}
}
public
void
dragExit
(
DropTargetEvent
dte
)
{
}
public
void
drop
(
DropTargetDropEvent
dtde
)
{
dtde
.
acceptDrop
(
DnDConstants
.
ACTION_COPY_OR_MOVE
);
if
(
dtde
.
isDataFlavorSupported
(
DataFlavor
.
javaFileListFlavor
))
{
try
{
content
=
(
java
.
util
.
List
)
dtde
.
getTransferable
().
getTransferData
(
DataFlavor
.
javaFileListFlavor
);
repaint
();
}
catch
(
UnsupportedFlavorException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
dtde
.
dropComplete
(
true
);
boolean
listsAreEqual
=
true
;
for
(
int
i
=
0
;
i
<
content
.
size
();
i
++)
{
if
(!
FileListTransferable
.
files
[
i
].
getName
().
equals
(
content
.
get
(
i
).
getName
()))
{
listsAreEqual
=
false
;
}
}
if
(
listsAreEqual
)
{
System
.
err
.
println
(
InterprocessMessages
.
EXECUTION_IS_SUCCESSFULL
);
System
.
exit
(
0
);
}
}
dtde
.
rejectDrop
();
System
.
err
.
println
(
InterprocessMessages
.
FILES_ON_TARGET_ARE_CORRUPTED
);
System
.
exit
(
1
);
}
public
void
paint
(
Graphics
g
)
{
g
.
setColor
(
Color
.
YELLOW
);
int
i
=
0
;
for
(
Iterator
<
File
>
iterator
=
content
.
iterator
();
iterator
.
hasNext
();
i
++)
{
g
.
drawString
(
iterator
.
next
().
getName
(),
5
,
g
.
getFontMetrics
().
getAscent
()*
i
+
20
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录