Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
12e00c83
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看板
提交
12e00c83
编写于
3月 25, 2011
作者:
M
mrkam
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7027686: /applets/MoleculeViewer demo needs to be improved
Reviewed-by: alexp
上级
eae7f2e0
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
266 addition
and
209 deletion
+266
-209
src/share/demo/applets/MoleculeViewer/Matrix3D.java
src/share/demo/applets/MoleculeViewer/Matrix3D.java
+19
-9
src/share/demo/applets/MoleculeViewer/XYZApp.java
src/share/demo/applets/MoleculeViewer/XYZApp.java
+241
-194
src/share/demo/applets/MoleculeViewer/example1.html
src/share/demo/applets/MoleculeViewer/example1.html
+1
-1
src/share/demo/applets/MoleculeViewer/example2.html
src/share/demo/applets/MoleculeViewer/example2.html
+1
-1
src/share/demo/applets/MoleculeViewer/example3.html
src/share/demo/applets/MoleculeViewer/example3.html
+4
-4
未找到文件。
src/share/demo/applets/MoleculeViewer/Matrix3D.java
浏览文件 @
12e00c83
/*
/*
* Copyright (c) 1995, 20
06
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1995, 20
11
, Oracle and/or its affiliates. All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* modification, are permitted provided that the following conditions
...
@@ -29,22 +29,23 @@
...
@@ -29,22 +29,23 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
*/
/*
*/
/** A fairly conventional 3D matrix object that can transform sets of
/** A fairly conventional 3D matrix object that can transform sets of
3D points and perform a variety of manipulations on the transform */
3D points and perform a variety of manipulations on the transform */
class
Matrix3D
{
class
Matrix3D
{
float
xx
,
xy
,
xz
,
xo
;
float
xx
,
xy
,
xz
,
xo
;
float
yx
,
yy
,
yz
,
yo
;
float
yx
,
yy
,
yz
,
yo
;
float
zx
,
zy
,
zz
,
zo
;
float
zx
,
zy
,
zz
,
zo
;
static
final
double
pi
=
3.14159265
;
static
final
double
pi
=
3.14159265
;
/** Create a new unit matrix */
/** Create a new unit matrix */
Matrix3D
()
{
Matrix3D
()
{
xx
=
1.0f
;
xx
=
1.0f
;
yy
=
1.0f
;
yy
=
1.0f
;
zz
=
1.0f
;
zz
=
1.0f
;
}
}
/** Scale by f in all dimensions */
/** Scale by f in all dimensions */
void
scale
(
float
f
)
{
void
scale
(
float
f
)
{
xx
*=
f
;
xx
*=
f
;
...
@@ -60,6 +61,7 @@ class Matrix3D {
...
@@ -60,6 +61,7 @@ class Matrix3D {
zz
*=
f
;
zz
*=
f
;
zo
*=
f
;
zo
*=
f
;
}
}
/** Scale along each axis independently */
/** Scale along each axis independently */
void
scale
(
float
xf
,
float
yf
,
float
zf
)
{
void
scale
(
float
xf
,
float
yf
,
float
zf
)
{
xx
*=
xf
;
xx
*=
xf
;
...
@@ -75,12 +77,14 @@ class Matrix3D {
...
@@ -75,12 +77,14 @@ class Matrix3D {
zz
*=
zf
;
zz
*=
zf
;
zo
*=
zf
;
zo
*=
zf
;
}
}
/** Translate the origin */
/** Translate the origin */
void
translate
(
float
x
,
float
y
,
float
z
)
{
void
translate
(
float
x
,
float
y
,
float
z
)
{
xo
+=
x
;
xo
+=
x
;
yo
+=
y
;
yo
+=
y
;
zo
+=
z
;
zo
+=
z
;
}
}
/** rotate theta degrees about the y axis */
/** rotate theta degrees about the y axis */
void
yrot
(
double
theta
)
{
void
yrot
(
double
theta
)
{
theta
*=
(
pi
/
180
);
theta
*=
(
pi
/
180
);
...
@@ -106,6 +110,7 @@ class Matrix3D {
...
@@ -106,6 +110,7 @@ class Matrix3D {
zy
=
Nzy
;
zy
=
Nzy
;
zz
=
Nzz
;
zz
=
Nzz
;
}
}
/** rotate theta degrees about the x axis */
/** rotate theta degrees about the x axis */
void
xrot
(
double
theta
)
{
void
xrot
(
double
theta
)
{
theta
*=
(
pi
/
180
);
theta
*=
(
pi
/
180
);
...
@@ -131,6 +136,7 @@ class Matrix3D {
...
@@ -131,6 +136,7 @@ class Matrix3D {
zy
=
Nzy
;
zy
=
Nzy
;
zz
=
Nzz
;
zz
=
Nzz
;
}
}
/** rotate theta degrees about the z axis */
/** rotate theta degrees about the z axis */
void
zrot
(
double
theta
)
{
void
zrot
(
double
theta
)
{
theta
*=
(
pi
/
180
);
theta
*=
(
pi
/
180
);
...
@@ -156,6 +162,7 @@ class Matrix3D {
...
@@ -156,6 +162,7 @@ class Matrix3D {
xy
=
Nxy
;
xy
=
Nxy
;
xz
=
Nxz
;
xz
=
Nxz
;
}
}
/** Multiply this matrix by a second: M = M*R */
/** Multiply this matrix by a second: M = M*R */
void
mult
(
Matrix3D
rhs
)
{
void
mult
(
Matrix3D
rhs
)
{
float
lxx
=
xx
*
rhs
.
xx
+
yx
*
rhs
.
xy
+
zx
*
rhs
.
xz
;
float
lxx
=
xx
*
rhs
.
xx
+
yx
*
rhs
.
xy
+
zx
*
rhs
.
xz
;
...
@@ -204,6 +211,7 @@ class Matrix3D {
...
@@ -204,6 +211,7 @@ class Matrix3D {
zy
=
0
;
zy
=
0
;
zz
=
1
;
zz
=
1
;
}
}
/** Transform nvert points from v into tv. v contains the input
/** Transform nvert points from v into tv. v contains the input
coordinates in floating point. Three successive entries in
coordinates in floating point. Three successive entries in
the array constitute a point. tv ends up holding the transformed
the array constitute a point. tv ends up holding the transformed
...
@@ -216,11 +224,13 @@ class Matrix3D {
...
@@ -216,11 +224,13 @@ class Matrix3D {
float
x
=
v
[
i
];
float
x
=
v
[
i
];
float
y
=
v
[
i
+
1
];
float
y
=
v
[
i
+
1
];
float
z
=
v
[
i
+
2
];
float
z
=
v
[
i
+
2
];
tv
[
i
]
=
(
int
)
(
x
*
lxx
+
y
*
lxy
+
z
*
lxz
+
lxo
);
tv
[
i
]
=
(
int
)
(
x
*
lxx
+
y
*
lxy
+
z
*
lxz
+
lxo
);
tv
[
i
+
1
]
=
(
int
)
(
x
*
lyx
+
y
*
lyy
+
z
*
lyz
+
lyo
);
tv
[
i
+
1
]
=
(
int
)
(
x
*
lyx
+
y
*
lyy
+
z
*
lyz
+
lyo
);
tv
[
i
+
2
]
=
(
int
)
(
x
*
lzx
+
y
*
lzy
+
z
*
lzz
+
lzo
);
tv
[
i
+
2
]
=
(
int
)
(
x
*
lzx
+
y
*
lzy
+
z
*
lzz
+
lzo
);
}
}
}
}
@Override
public
String
toString
()
{
public
String
toString
()
{
return
(
"["
+
xo
+
","
+
xx
+
","
+
xy
+
","
+
xz
+
";"
return
(
"["
+
xo
+
","
+
xx
+
","
+
xy
+
","
+
xz
+
";"
+
yo
+
","
+
yx
+
","
+
yy
+
","
+
yz
+
";"
+
yo
+
","
+
yx
+
","
+
yy
+
","
+
yz
+
";"
...
...
src/share/demo/applets/MoleculeViewer/XYZApp.java
浏览文件 @
12e00c83
/*
/*
* Copyright (c) 1995, 20
06
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1995, 20
11
, Oracle and/or its affiliates. All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* modification, are permitted provided that the following conditions
...
@@ -29,37 +29,43 @@
...
@@ -29,37 +29,43 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
*/
/*
*/
/*
* A set of classes to parse, represent and display Chemical compounds in
* .xyz format (see http://chem.leeds.ac.uk/Project/MIME.html)
*/
import
java.applet.Applet
;
import
java.applet.Applet
;
import
java.awt.Image
;
import
java.awt.Image
;
import
java.awt.Event
;
import
java.awt.Graphics
;
import
java.awt.Graphics
;
import
java.awt.Dimension
;
import
java.awt.Dimension
;
import
java.io.*
;
import
java.awt.event.MouseEvent
;
import
java.awt.event.MouseListener
;
import
java.awt.event.MouseMotionListener
;
import
java.net.URL
;
import
java.net.URL
;
import
java.util.Hashtable
;
import
java.awt.image.IndexColorModel
;
import
java.awt.image.IndexColorModel
;
import
java.awt.image.ColorModel
;
import
java.awt.image.MemoryImageSource
;
import
java.awt.image.MemoryImageSource
;
import
java.awt.event.*
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.io.StreamTokenizer
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
/*
* A set of classes to parse, represent and display Chemical compounds in
* .xyz format (see http://chem.leeds.ac.uk/Project/MIME.html)
*/
/** The representation of a Chemical .xyz model */
/** The representation of a Chemical .xyz model */
class
XYZChemModel
{
final
class
XYZChemModel
{
float
vert
[];
float
vert
[];
Atom
atoms
[];
Atom
atoms
[];
int
tvert
[];
int
tvert
[];
int
ZsortMap
[];
int
ZsortMap
[];
int
nvert
,
maxvert
;
int
nvert
,
maxvert
;
static
final
Map
<
String
,
Atom
>
atomTable
=
new
HashMap
<
String
,
Atom
>();
static
Hashtable
atomTable
=
new
Hashtable
();
static
Atom
defaultAtom
;
static
Atom
defaultAtom
;
static
{
static
{
atomTable
.
put
(
"c"
,
new
Atom
(
0
,
0
,
0
));
atomTable
.
put
(
"c"
,
new
Atom
(
0
,
0
,
0
));
atomTable
.
put
(
"h"
,
new
Atom
(
210
,
210
,
210
));
atomTable
.
put
(
"h"
,
new
Atom
(
210
,
210
,
210
));
...
@@ -70,58 +76,51 @@ class XYZChemModel {
...
@@ -70,58 +76,51 @@ class XYZChemModel {
atomTable
.
put
(
"hn"
,
new
Atom
(
150
,
255
,
150
));
/* !!*/
atomTable
.
put
(
"hn"
,
new
Atom
(
150
,
255
,
150
));
/* !!*/
defaultAtom
=
new
Atom
(
255
,
100
,
200
);
defaultAtom
=
new
Atom
(
255
,
100
,
200
);
}
}
boolean
transformed
;
boolean
transformed
;
Matrix3D
mat
;
Matrix3D
mat
;
float
xmin
,
xmax
,
ymin
,
ymax
,
zmin
,
zmax
;
float
xmin
,
xmax
,
ymin
,
ymax
,
zmin
,
zmax
;
XYZChemModel
()
{
XYZChemModel
()
{
mat
=
new
Matrix3D
();
mat
=
new
Matrix3D
();
mat
.
xrot
(
20
);
mat
.
xrot
(
20
);
mat
.
yrot
(
30
);
mat
.
yrot
(
30
);
}
}
/** Create a Chemical model by parsing an input stream */
/** Create a Cehmical model by parsing an input stream */
XYZChemModel
(
InputStream
is
)
throws
Exception
{
XYZChemModel
(
InputStream
is
)
throws
Exception
{
this
();
this
();
StreamTokenizer
st
=
new
StreamTokenizer
(
StreamTokenizer
st
=
new
StreamTokenizer
(
new
BufferedReader
(
new
InputStreamReader
(
is
,
"UTF-8"
)));
new
BufferedReader
(
new
InputStreamReader
(
is
,
"UTF-8"
)));
st
.
eolIsSignificant
(
true
);
st
.
eolIsSignificant
(
true
);
st
.
commentChar
(
'#'
);
st
.
commentChar
(
'#'
);
int
slot
=
0
;
try
{
try
scan:
{
while
(
true
)
{
scan:
switch
(
st
.
nextToken
())
{
while
(
true
)
{
switch
(
st
.
nextToken
()
)
{
case
StreamTokenizer
.
TT_EOF
:
case
StreamTokenizer
.
TT_EOF
:
break
scan
;
break
scan
;
default
:
default
:
break
;
break
;
case
StreamTokenizer
.
TT_WORD
:
case
StreamTokenizer
.
TT_WORD
:
String
name
=
st
.
sval
;
String
name
=
st
.
sval
;
double
x
=
0
,
y
=
0
,
z
=
0
;
double
x
=
0
,
if
(
st
.
nextToken
()
==
StreamTokenizer
.
TT_NUMBER
)
y
=
0
,
{
z
=
0
;
if
(
st
.
nextToken
()
==
StreamTokenizer
.
TT_NUMBER
)
{
x
=
st
.
nval
;
x
=
st
.
nval
;
if
(
st
.
nextToken
()
==
StreamTokenizer
.
TT_NUMBER
)
if
(
st
.
nextToken
()
==
StreamTokenizer
.
TT_NUMBER
)
{
{
y
=
st
.
nval
;
y
=
st
.
nval
;
if
(
st
.
nextToken
()
==
StreamTokenizer
.
TT_NUMBER
)
if
(
st
.
nextToken
()
==
StreamTokenizer
.
TT_NUMBER
)
{
z
=
st
.
nval
;
z
=
st
.
nval
;
}
}
}
}
}
addVert
(
name
,
(
float
)
x
,
(
float
)
y
,
(
float
)
z
);
addVert
(
name
,
(
float
)
x
,
(
float
)
y
,
(
float
)
z
);
while
(
st
.
ttype
!=
StreamTokenizer
.
TT_EOL
&&
while
(
st
.
ttype
!=
StreamTokenizer
.
TT_EOL
st
.
ttype
!=
StreamTokenizer
.
TT_EOF
)
&&
st
.
ttype
!=
StreamTokenizer
.
TT_EOF
)
{
st
.
nextToken
();
st
.
nextToken
();
}
}
// end Switch
}
// end Switch
...
@@ -130,17 +129,19 @@ scan:
...
@@ -130,17 +129,19 @@ scan:
is
.
close
();
is
.
close
();
}
// end Try
}
// end Try
catch
(
IOException
e
)
{}
catch
(
IOException
e
)
{
}
if
(
st
.
ttype
!=
StreamTokenizer
.
TT_EOF
)
if
(
st
.
ttype
!=
StreamTokenizer
.
TT_EOF
)
{
throw
new
Exception
(
st
.
toString
());
throw
new
Exception
(
st
.
toString
());
}
}
// end XYZChemModel()
}
// end XYZChemModel()
/** Add a vertex to this model */
/** Add a vertex to this model */
int
addVert
(
String
name
,
float
x
,
float
y
,
float
z
)
{
int
addVert
(
String
name
,
float
x
,
float
y
,
float
z
)
{
int
i
=
nvert
;
int
i
=
nvert
;
if
(
i
>=
maxvert
)
if
(
i
>=
maxvert
)
{
if
(
vert
==
null
)
{
if
(
vert
==
null
)
{
maxvert
=
100
;
maxvert
=
100
;
vert
=
new
float
[
maxvert
*
3
];
vert
=
new
float
[
maxvert
*
3
];
...
@@ -154,8 +155,11 @@ scan:
...
@@ -154,8 +155,11 @@ scan:
System
.
arraycopy
(
atoms
,
0
,
na
,
0
,
atoms
.
length
);
System
.
arraycopy
(
atoms
,
0
,
na
,
0
,
atoms
.
length
);
atoms
=
na
;
atoms
=
na
;
}
}
Atom
a
=
(
Atom
)
atomTable
.
get
(
name
.
toLowerCase
());
}
if
(
a
==
null
)
a
=
defaultAtom
;
Atom
a
=
atomTable
.
get
(
name
.
toLowerCase
());
if
(
a
==
null
)
{
a
=
defaultAtom
;
}
atoms
[
i
]
=
a
;
atoms
[
i
]
=
a
;
i
*=
3
;
i
*=
3
;
vert
[
i
]
=
x
;
vert
[
i
]
=
x
;
...
@@ -166,30 +170,33 @@ scan:
...
@@ -166,30 +170,33 @@ scan:
/** Transform all the points in this model */
/** Transform all the points in this model */
void
transform
()
{
void
transform
()
{
if
(
transformed
||
nvert
<=
0
)
if
(
transformed
||
nvert
<=
0
)
{
return
;
return
;
if
(
tvert
==
null
||
tvert
.
length
<
nvert
*
3
)
}
if
(
tvert
==
null
||
tvert
.
length
<
nvert
*
3
)
{
tvert
=
new
int
[
nvert
*
3
];
tvert
=
new
int
[
nvert
*
3
];
}
mat
.
transform
(
vert
,
tvert
,
nvert
);
mat
.
transform
(
vert
,
tvert
,
nvert
);
transformed
=
true
;
transformed
=
true
;
}
}
/** Paint this model to a graphics context. It uses the matrix associated
/** Paint this model to a graphics context. It uses the matrix associated
with this model to map from model space to screen space.
with this model to map from model space to screen space.
The next version of the browser should have double buffering,
The next version of the browser should have double buffering,
which will make this *much* nicer */
which will make this *much* nicer */
void
paint
(
Graphics
g
)
{
void
paint
(
Graphics
g
)
{
if
(
vert
==
null
||
nvert
<=
0
)
if
(
vert
==
null
||
nvert
<=
0
)
{
return
;
return
;
}
transform
();
transform
();
int
v
[]
=
tvert
;
int
v
[]
=
tvert
;
int
zs
[]
=
ZsortMap
;
int
zs
[]
=
ZsortMap
;
if
(
zs
==
null
)
{
if
(
zs
==
null
)
{
ZsortMap
=
zs
=
new
int
[
nvert
];
ZsortMap
=
zs
=
new
int
[
nvert
];
for
(
int
i
=
nvert
;
--
i
>=
0
;)
for
(
int
i
=
nvert
;
--
i
>=
0
;)
{
zs
[
i
]
=
i
*
3
;
zs
[
i
]
=
i
*
3
;
}
}
}
/*
/*
* I use a bubble sort since from one iteration to the next, the sort
* I use a bubble sort since from one iteration to the next, the sort
...
@@ -209,24 +216,26 @@ scan:
...
@@ -209,24 +216,26 @@ scan:
flipped
=
true
;
flipped
=
true
;
}
}
}
}
if
(!
flipped
)
if
(!
flipped
)
{
break
;
break
;
}
}
}
int
lg
=
0
;
int
lim
=
nvert
;
int
lim
=
nvert
;
Atom
ls
[]
=
atoms
;
if
(
lim
<=
0
||
nvert
<=
0
)
{
if
(
lim
<=
0
||
nvert
<=
0
)
return
;
return
;
}
for
(
int
i
=
0
;
i
<
lim
;
i
++)
{
for
(
int
i
=
0
;
i
<
lim
;
i
++)
{
int
j
=
zs
[
i
];
int
j
=
zs
[
i
];
int
grey
=
v
[
j
+
2
];
int
grey
=
v
[
j
+
2
];
if
(
grey
<
0
)
if
(
grey
<
0
)
{
grey
=
0
;
grey
=
0
;
if
(
grey
>
15
)
}
if
(
grey
>
15
)
{
grey
=
15
;
grey
=
15
;
}
// g.drawString(names[i], v[j], v[j+1]);
// g.drawString(names[i], v[j], v[j+1]);
atoms
[
j
/
3
].
paint
(
g
,
v
[
j
],
v
[
j
+
1
],
grey
);
atoms
[
j
/
3
].
paint
(
g
,
v
[
j
],
v
[
j
+
1
],
grey
);
// g.drawImage(iBall, v[j] - (iBall.width >> 1), v[j + 1] -
// g.drawImage(iBall, v[j] - (iBall.width >> 1), v[j + 1] -
// (iBall.height >> 1));
// (iBall.height >> 1));
}
}
...
@@ -234,47 +243,55 @@ scan:
...
@@ -234,47 +243,55 @@ scan:
/** Find the bounding box of this model */
/** Find the bounding box of this model */
void
findBB
()
{
void
findBB
()
{
if
(
nvert
<=
0
)
if
(
nvert
<=
0
)
{
return
;
return
;
}
float
v
[]
=
vert
;
float
v
[]
=
vert
;
float
xmin
=
v
[
0
],
xmax
=
xmin
;
float
_xmin
=
v
[
0
],
_xmax
=
_
xmin
;
float
ymin
=
v
[
1
],
ymax
=
ymin
;
float
_ymin
=
v
[
1
],
_ymax
=
_
ymin
;
float
zmin
=
v
[
2
],
zmax
=
zmin
;
float
_zmin
=
v
[
2
],
_zmax
=
_
zmin
;
for
(
int
i
=
nvert
*
3
;
(
i
-=
3
)
>
0
;)
{
for
(
int
i
=
nvert
*
3
;
(
i
-=
3
)
>
0
;)
{
float
x
=
v
[
i
];
float
x
=
v
[
i
];
if
(
x
<
xmin
)
if
(
x
<
_xmin
)
{
xmin
=
x
;
_xmin
=
x
;
if
(
x
>
xmax
)
}
xmax
=
x
;
if
(
x
>
_xmax
)
{
_xmax
=
x
;
}
float
y
=
v
[
i
+
1
];
float
y
=
v
[
i
+
1
];
if
(
y
<
ymin
)
if
(
y
<
_ymin
)
{
ymin
=
y
;
_ymin
=
y
;
if
(
y
>
ymax
)
}
ymax
=
y
;
if
(
y
>
_ymax
)
{
_ymax
=
y
;
}
float
z
=
v
[
i
+
2
];
float
z
=
v
[
i
+
2
];
if
(
z
<
zmin
)
if
(
z
<
_zmin
)
{
zmin
=
z
;
_zmin
=
z
;
if
(
z
>
zmax
)
}
zmax
=
z
;
if
(
z
>
_zmax
)
{
}
_zmax
=
z
;
this
.
xmax
=
xmax
;
}
this
.
xmin
=
xmin
;
}
this
.
ymax
=
ymax
;
this
.
xmax
=
_xmax
;
this
.
ymin
=
ymin
;
this
.
xmin
=
_xmin
;
this
.
zmax
=
zmax
;
this
.
ymax
=
_ymax
;
this
.
zmin
=
zmin
;
this
.
ymin
=
_ymin
;
this
.
zmax
=
_zmax
;
this
.
zmin
=
_zmin
;
}
}
}
}
/** An applet to put a Chemical model into a page */
/** An applet to put a Chemical model into a page */
public
class
XYZApp
@SuppressWarnings
(
"serial"
)
extends
Applet
public
class
XYZApp
extends
Applet
implements
Runnable
,
MouseListener
,
implements
Runnable
,
MouseListener
,
MouseMotionListener
{
MouseMotionListener
{
XYZChemModel
md
;
XYZChemModel
md
;
boolean
painted
=
true
;
boolean
painted
=
true
;
float
xfac
;
float
xfac
;
int
prevx
,
prevy
;
int
prevx
,
prevy
;
float
xtheta
,
ytheta
;
float
scalefudge
=
1
;
float
scalefudge
=
1
;
Matrix3D
amat
=
new
Matrix3D
(),
tmat
=
new
Matrix3D
();
Matrix3D
amat
=
new
Matrix3D
(),
tmat
=
new
Matrix3D
();
String
mdname
=
null
;
String
mdname
=
null
;
...
@@ -283,7 +300,6 @@ public class XYZApp
...
@@ -283,7 +300,6 @@ public class XYZApp
Graphics
backGC
;
Graphics
backGC
;
Dimension
backSize
;
Dimension
backSize
;
private
synchronized
void
newBackBuffer
()
{
private
synchronized
void
newBackBuffer
()
{
backBuffer
=
createImage
(
getSize
().
width
,
getSize
().
height
);
backBuffer
=
createImage
(
getSize
().
width
,
getSize
().
height
);
if
(
backGC
!=
null
)
{
if
(
backGC
!=
null
)
{
...
@@ -293,16 +309,18 @@ public class XYZApp
...
@@ -293,16 +309,18 @@ public class XYZApp
backSize
=
getSize
();
backSize
=
getSize
();
}
}
@Override
public
void
init
()
{
public
void
init
()
{
mdname
=
getParameter
(
"model"
);
mdname
=
getParameter
(
"model"
);
try
{
try
{
scalefudge
=
Float
.
valueOf
(
getParameter
(
"scale"
)).
floatValue
();
scalefudge
=
Float
.
valueOf
(
getParameter
(
"scale"
)).
floatValue
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
ignored
)
{
}
;
}
amat
.
yrot
(
20
);
amat
.
yrot
(
20
);
amat
.
xrot
(
20
);
amat
.
xrot
(
20
);
if
(
mdname
==
null
)
if
(
mdname
==
null
)
{
mdname
=
"model.obj"
;
mdname
=
"model.obj"
;
}
resize
(
getSize
().
width
<=
20
?
400
:
getSize
().
width
,
resize
(
getSize
().
width
<=
20
?
400
:
getSize
().
width
,
getSize
().
height
<=
20
?
400
:
getSize
().
height
);
getSize
().
height
<=
20
?
400
:
getSize
().
height
);
newBackBuffer
();
newBackBuffer
();
...
@@ -310,62 +328,84 @@ public class XYZApp
...
@@ -310,62 +328,84 @@ public class XYZApp
addMouseMotionListener
(
this
);
addMouseMotionListener
(
this
);
}
}
@Override
public
void
destroy
()
{
public
void
destroy
()
{
removeMouseListener
(
this
);
removeMouseListener
(
this
);
removeMouseMotionListener
(
this
);
removeMouseMotionListener
(
this
);
}
}
@Override
public
void
run
()
{
public
void
run
()
{
InputStream
is
=
null
;
InputStream
is
=
null
;
try
{
try
{
Thread
.
currentThread
().
setPriority
(
Thread
.
MIN_PRIORITY
);
Thread
.
currentThread
().
setPriority
(
Thread
.
MIN_PRIORITY
);
is
=
new
URL
(
getDocumentBase
(),
mdname
).
openStream
();
is
=
new
URL
(
getDocumentBase
(),
mdname
).
openStream
();
XYZChemModel
m
=
new
XYZChemModel
(
is
);
XYZChemModel
m
=
new
XYZChemModel
(
is
);
Atom
.
setApplet
(
this
);
Atom
.
setApplet
(
this
);
md
=
m
;
md
=
m
;
m
.
findBB
();
m
.
findBB
();
float
xw
=
m
.
xmax
-
m
.
xmin
;
float
xw
=
m
.
xmax
-
m
.
xmin
;
float
yw
=
m
.
ymax
-
m
.
ymin
;
float
yw
=
m
.
ymax
-
m
.
ymin
;
float
zw
=
m
.
zmax
-
m
.
zmin
;
float
zw
=
m
.
zmax
-
m
.
zmin
;
if
(
yw
>
xw
)
if
(
yw
>
xw
)
{
xw
=
yw
;
xw
=
yw
;
if
(
zw
>
xw
)
}
if
(
zw
>
xw
)
{
xw
=
zw
;
xw
=
zw
;
}
float
f1
=
getSize
().
width
/
xw
;
float
f1
=
getSize
().
width
/
xw
;
float
f2
=
getSize
().
height
/
xw
;
float
f2
=
getSize
().
height
/
xw
;
xfac
=
0.7f
*
(
f1
<
f2
?
f1
:
f2
)
*
scalefudge
;
xfac
=
0.7f
*
(
f1
<
f2
?
f1
:
f2
)
*
scalefudge
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
(
);
Logger
.
getLogger
(
XYZApp
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
e
);
md
=
null
;
md
=
null
;
message
=
e
.
toString
();
message
=
e
.
toString
();
}
}
try
{
try
{
if
(
is
!=
null
)
if
(
is
!=
null
)
{
is
.
close
();
is
.
close
();
}
catch
(
Exception
e
)
{
}
}
catch
(
Exception
ignored
)
{
}
}
repaint
();
repaint
();
}
}
@Override
public
void
start
()
{
public
void
start
()
{
if
(
md
==
null
&&
message
==
null
)
if
(
md
==
null
&&
message
==
null
)
{
new
Thread
(
this
).
start
();
new
Thread
(
this
).
start
();
}
}
}
@Override
public
void
stop
()
{
public
void
stop
()
{
}
}
/* event handling */
/* event handling */
@Override
public
void
mouseClicked
(
MouseEvent
e
)
{
public
void
mouseClicked
(
MouseEvent
e
)
{
}
}
@Override
public
void
mousePressed
(
MouseEvent
e
)
{
public
void
mousePressed
(
MouseEvent
e
)
{
prevx
=
e
.
getX
();
prevx
=
e
.
getX
();
prevy
=
e
.
getY
();
prevy
=
e
.
getY
();
e
.
consume
();
e
.
consume
();
}
}
@Override
public
void
mouseReleased
(
MouseEvent
e
)
{
public
void
mouseReleased
(
MouseEvent
e
)
{
}
}
@Override
public
void
mouseEntered
(
MouseEvent
e
)
{
public
void
mouseEntered
(
MouseEvent
e
)
{
}
}
@Override
public
void
mouseExited
(
MouseEvent
e
)
{
public
void
mouseExited
(
MouseEvent
e
)
{
}
}
@Override
public
void
mouseDragged
(
MouseEvent
e
)
{
public
void
mouseDragged
(
MouseEvent
e
)
{
int
x
=
e
.
getX
();
int
x
=
e
.
getX
();
int
y
=
e
.
getY
();
int
y
=
e
.
getY
();
...
@@ -383,15 +423,20 @@ public class XYZApp
...
@@ -383,15 +423,20 @@ public class XYZApp
prevy
=
y
;
prevy
=
y
;
e
.
consume
();
e
.
consume
();
}
}
@Override
public
void
mouseMoved
(
MouseEvent
e
)
{
public
void
mouseMoved
(
MouseEvent
e
)
{
}
}
@Override
public
void
update
(
Graphics
g
)
{
public
void
update
(
Graphics
g
)
{
if
(
backBuffer
==
null
)
if
(
backBuffer
==
null
)
{
g
.
clearRect
(
0
,
0
,
getSize
().
width
,
getSize
().
height
);
g
.
clearRect
(
0
,
0
,
getSize
().
width
,
getSize
().
height
);
}
paint
(
g
);
paint
(
g
);
}
}
@Override
public
void
paint
(
Graphics
g
)
{
public
void
paint
(
Graphics
g
)
{
if
(
md
!=
null
)
{
if
(
md
!=
null
)
{
md
.
mat
.
unit
();
md
.
mat
.
unit
();
...
@@ -404,53 +449,50 @@ public class XYZApp
...
@@ -404,53 +449,50 @@ public class XYZApp
md
.
mat
.
translate
(
getSize
().
width
/
2
,
getSize
().
height
/
2
,
8
);
md
.
mat
.
translate
(
getSize
().
width
/
2
,
getSize
().
height
/
2
,
8
);
md
.
transformed
=
false
;
md
.
transformed
=
false
;
if
(
backBuffer
!=
null
)
{
if
(
backBuffer
!=
null
)
{
if
(!
backSize
.
equals
(
getSize
()))
if
(!
backSize
.
equals
(
getSize
()))
{
newBackBuffer
();
newBackBuffer
();
}
backGC
.
setColor
(
getBackground
());
backGC
.
setColor
(
getBackground
());
backGC
.
fillRect
(
0
,
0
,
getSize
().
width
,
getSize
().
height
);
backGC
.
fillRect
(
0
,
0
,
getSize
().
width
,
getSize
().
height
);
md
.
paint
(
backGC
);
md
.
paint
(
backGC
);
g
.
drawImage
(
backBuffer
,
0
,
0
,
this
);
g
.
drawImage
(
backBuffer
,
0
,
0
,
this
);
}
}
else
{
else
md
.
paint
(
g
);
md
.
paint
(
g
);
}
setPainted
();
setPainted
();
}
else
if
(
message
!=
null
)
{
}
else
if
(
message
!=
null
)
{
g
.
drawString
(
"Error in model:"
,
3
,
20
);
g
.
drawString
(
"Error in model:"
,
3
,
20
);
g
.
drawString
(
message
,
10
,
40
);
g
.
drawString
(
message
,
10
,
40
);
}
}
}
}
private
synchronized
void
setPainted
()
{
private
synchronized
void
setPainted
()
{
painted
=
true
;
painted
=
true
;
notifyAll
();
notifyAll
();
}
}
private
synchronized
void
waitPainted
()
@Override
{
while
(!
painted
)
{
try
{
wait
();
}
catch
(
InterruptedException
e
)
{}
}
painted
=
false
;
}
public
String
getAppletInfo
()
{
public
String
getAppletInfo
()
{
return
"Title: XYZApp \nAuthor: James Gosling \nAn applet to put a Chemical model into a page."
;
return
"Title: XYZApp \nAuthor: James Gosling \nAn applet to put"
+
" a Chemical model into a page."
;
}
}
@Override
public
String
[][]
getParameterInfo
()
{
public
String
[][]
getParameterInfo
()
{
String
[][]
info
=
{
String
[][]
info
=
{
{
"model"
,
"path string"
,
"The path to the model to be displayed in .xyz format (see http://chem.leeds.ac.uk/Project/MIME.html). Default is model.obj."
},
{
"model"
,
"path string"
,
"The path to the model to be displayed"
{
"scale"
,
"float"
,
"Scale factor. Default is 1 (i.e. no scale)."
}
+
" in .xyz format "
+
"(see http://chem.leeds.ac.uk/Project/MIME.html)."
+
" Default is model.obj."
},
{
"scale"
,
"float"
,
"Scale factor. Default is 1 (i.e. no scale)."
}
};
};
return
info
;
return
info
;
}
}
}
// end class XYZApp
}
// end class XYZApp
class
Atom
{
class
Atom
{
private
static
Applet
applet
;
private
static
Applet
applet
;
private
static
byte
[]
data
;
private
static
byte
[]
data
;
private
final
static
int
R
=
40
;
private
final
static
int
R
=
40
;
...
@@ -459,7 +501,6 @@ class Atom {
...
@@ -459,7 +501,6 @@ class Atom {
private
final
static
int
bgGrey
=
192
;
private
final
static
int
bgGrey
=
192
;
private
final
static
int
nBalls
=
16
;
private
final
static
int
nBalls
=
16
;
private
static
int
maxr
;
private
static
int
maxr
;
private
int
Rl
;
private
int
Rl
;
private
int
Gl
;
private
int
Gl
;
private
int
Bl
;
private
int
Bl
;
...
@@ -475,24 +516,29 @@ class Atom {
...
@@ -475,24 +516,29 @@ class Atom {
int
x
=
X
+
hx
;
int
x
=
X
+
hx
;
int
y
=
Y
-
R
+
hy
;
int
y
=
Y
-
R
+
hy
;
int
r
=
(
int
)
(
Math
.
sqrt
(
x
*
x
+
y
*
y
)
+
0.5
);
int
r
=
(
int
)
(
Math
.
sqrt
(
x
*
x
+
y
*
y
)
+
0.5
);
if
(
r
>
mr
)
if
(
r
>
mr
)
{
mr
=
r
;
mr
=
r
;
}
data
[
p
++]
=
r
<=
0
?
1
:
(
byte
)
r
;
data
[
p
++]
=
r
<=
0
?
1
:
(
byte
)
r
;
}
}
}
}
maxr
=
mr
;
maxr
=
mr
;
}
}
static
void
setApplet
(
Applet
app
)
{
static
void
setApplet
(
Applet
app
)
{
applet
=
app
;
applet
=
app
;
}
}
Atom
(
int
Rl
,
int
Gl
,
int
Bl
)
{
Atom
(
int
Rl
,
int
Gl
,
int
Bl
)
{
this
.
Rl
=
Rl
;
this
.
Rl
=
Rl
;
this
.
Gl
=
Gl
;
this
.
Gl
=
Gl
;
this
.
Bl
=
Bl
;
this
.
Bl
=
Bl
;
}
}
private
final
int
blend
(
int
fg
,
int
bg
,
float
fgfactor
)
{
private
int
blend
(
int
fg
,
int
bg
,
float
fgfactor
)
{
return
(
int
)
(
bg
+
(
fg
-
bg
)
*
fgfactor
);
return
(
int
)
(
bg
+
(
fg
-
bg
)
*
fgfactor
);
}
}
private
void
Setup
()
{
private
void
Setup
()
{
balls
=
new
Image
[
nBalls
];
balls
=
new
Image
[
nBalls
];
byte
red
[]
=
new
byte
[
256
];
byte
red
[]
=
new
byte
[
256
];
...
@@ -502,7 +548,7 @@ class Atom {
...
@@ -502,7 +548,7 @@ class Atom {
byte
blue
[]
=
new
byte
[
256
];
byte
blue
[]
=
new
byte
[
256
];
blue
[
0
]
=
(
byte
)
bgGrey
;
blue
[
0
]
=
(
byte
)
bgGrey
;
for
(
int
r
=
0
;
r
<
nBalls
;
r
++)
{
for
(
int
r
=
0
;
r
<
nBalls
;
r
++)
{
float
b
=
(
float
)
(
r
+
1
)
/
nBalls
;
float
b
=
(
float
)
(
r
+
1
)
/
nBalls
;
for
(
int
i
=
maxr
;
i
>=
1
;
--
i
)
{
for
(
int
i
=
maxr
;
i
>=
1
;
--
i
)
{
float
d
=
(
float
)
i
/
maxr
;
float
d
=
(
float
)
i
/
maxr
;
red
[
i
]
=
(
byte
)
blend
(
blend
(
Rl
,
255
,
d
),
bgGrey
,
b
);
red
[
i
]
=
(
byte
)
blend
(
blend
(
Rl
,
255
,
d
),
bgGrey
,
b
);
...
@@ -512,9 +558,10 @@ class Atom {
...
@@ -512,9 +558,10 @@ class Atom {
IndexColorModel
model
=
new
IndexColorModel
(
8
,
maxr
+
1
,
IndexColorModel
model
=
new
IndexColorModel
(
8
,
maxr
+
1
,
red
,
green
,
blue
,
0
);
red
,
green
,
blue
,
0
);
balls
[
r
]
=
applet
.
createImage
(
balls
[
r
]
=
applet
.
createImage
(
new
MemoryImageSource
(
R
*
2
,
R
*
2
,
model
,
data
,
0
,
R
*
2
));
new
MemoryImageSource
(
R
*
2
,
R
*
2
,
model
,
data
,
0
,
R
*
2
));
}
}
}
}
void
paint
(
Graphics
gc
,
int
x
,
int
y
,
int
r
)
{
void
paint
(
Graphics
gc
,
int
x
,
int
y
,
int
r
)
{
Image
ba
[]
=
balls
;
Image
ba
[]
=
balls
;
if
(
ba
==
null
)
{
if
(
ba
==
null
)
{
...
...
src/share/demo/applets/MoleculeViewer/example1.html
浏览文件 @
12e00c83
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
<h1>
MoleculeViewer (example 1)
</h1>
<h1>
MoleculeViewer (example 1)
</h1>
<hr>
<hr>
<applet
code=
XYZApp.class
width=
300
height=
300
>
<applet
code=
XYZApp.class
width=
300
height=
300
>
<param
name=
model
value=
models/HyaluronicAcid.xyz
>
<param
name=
model
value=
"models/HyaluronicAcid.xyz"
>
alt="Your browser understands the
<
APPLET
>
tag but isn't running the applet, for some reason."
alt="Your browser understands the
<
APPLET
>
tag but isn't running the applet, for some reason."
Your browser is completely ignoring the
<
APPLET
>
tag!
Your browser is completely ignoring the
<
APPLET
>
tag!
</applet>
</applet>
...
...
src/share/demo/applets/MoleculeViewer/example2.html
浏览文件 @
12e00c83
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
<h1>
MoleculeViewer (example 2)
</h1>
<h1>
MoleculeViewer (example 2)
</h1>
<hr>
<hr>
<applet
code=
XYZApp.class
width=
300
height=
300
>
<applet
code=
XYZApp.class
width=
300
height=
300
>
<param
name=
model
value=
models/buckminsterfullerine.xyz
>
<param
name=
model
value=
"models/buckminsterfullerine.xyz"
>
alt="Your browser understands the
<
APPLET
>
tag but isn't running the applet, for some reason."
alt="Your browser understands the
<
APPLET
>
tag but isn't running the applet, for some reason."
Your browser is completely ignoring the
<
APPLET
>
tag!
Your browser is completely ignoring the
<
APPLET
>
tag!
</applet>
</applet>
...
...
src/share/demo/applets/MoleculeViewer/example3.html
浏览文件 @
12e00c83
...
@@ -6,25 +6,25 @@
...
@@ -6,25 +6,25 @@
<h1>
MoleculeViewer (example 3)
</h1>
<h1>
MoleculeViewer (example 3)
</h1>
<hr>
<hr>
<applet
code=
XYZApp.class
width=
100
height=
100
>
<applet
code=
XYZApp.class
width=
100
height=
100
>
<param
name=
model
value=
models/water.xyz
>
<param
name=
model
value=
"models/water.xyz"
>
alt="Your browser understands the
<
APPLET
>
tag but isn't running the applet, for some reason."
alt="Your browser understands the
<
APPLET
>
tag but isn't running the applet, for some reason."
Your browser is completely ignoring the
<
APPLET
>
tag!
Your browser is completely ignoring the
<
APPLET
>
tag!
</applet>
</applet>
<p>
<p>
<applet
code=
XYZApp.class
width=
100
height=
100
>
<applet
code=
XYZApp.class
width=
100
height=
100
>
<param
name=
model
value=
models/benzene.xyz
>
<param
name=
model
value=
"models/benzene.xyz"
>
alt="Your browser understands the
<
APPLET
>
tag but isn't running the applet, for some reason."
alt="Your browser understands the
<
APPLET
>
tag but isn't running the applet, for some reason."
Your browser is completely ignoring the
<
APPLET
>
tag!
Your browser is completely ignoring the
<
APPLET
>
tag!
</applet>
</applet>
<p>
<p>
<applet
code=
XYZApp.class
width=
100
height=
100
>
<applet
code=
XYZApp.class
width=
100
height=
100
>
<param
name=
model
value=
models/ethane.xyz
>
<param
name=
model
value=
"models/ethane.xyz"
>
alt="Your browser understands the
<
APPLET
>
tag but isn't running the applet, for some reason."
alt="Your browser understands the
<
APPLET
>
tag but isn't running the applet, for some reason."
Your browser is completely ignoring the
<
APPLET
>
tag!
Your browser is completely ignoring the
<
APPLET
>
tag!
</applet>
</applet>
<p>
<p>
<applet
code=
XYZApp.class
width=
100
height=
100
>
<applet
code=
XYZApp.class
width=
100
height=
100
>
<param
name=
model
value=
models/cyclohexane.xyz
>
<param
name=
model
value=
"models/cyclohexane.xyz"
>
alt="Your browser understands the
<
APPLET
>
tag but isn't running the applet, for some reason."
alt="Your browser understands the
<
APPLET
>
tag but isn't running the applet, for some reason."
Your browser is completely ignoring the
<
APPLET
>
tag!
Your browser is completely ignoring the
<
APPLET
>
tag!
</applet>
</applet>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录