Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
9927d4bc
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看板
提交
9927d4bc
编写于
3月 02, 2012
作者:
M
mrkam
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7130241: [macosx] TransparentRuler demo can not run due to lacking of perpixel transparency support
Reviewed-by: art
上级
e246f9d4
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
59 addition
and
28 deletion
+59
-28
src/share/demo/jfc/TransparentRuler/transparentruler/Ruler.java
...are/demo/jfc/TransparentRuler/transparentruler/Ruler.java
+59
-28
未找到文件。
src/share/demo/jfc/TransparentRuler/transparentruler/Ruler.java
浏览文件 @
9927d4bc
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011,
2012,
Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
...
...
@@ -40,12 +40,9 @@
package
transparentruler
;
import
java.awt.Color
;
import
java.awt.Graphics
;
import
java.awt.Graphics2D
;
import
java.awt.GraphicsDevice
;
import
java.awt.*
;
import
java.awt.GraphicsDevice.WindowTranslucency
;
import
java.awt.GraphicsEnvironment
;
import
static
java
.
awt
.
GraphicsDevice
.
WindowTranslucency
.*
;
import
java.awt.event.ActionEvent
;
import
java.awt.event.ComponentAdapter
;
import
java.awt.event.ComponentEvent
;
...
...
@@ -79,24 +76,17 @@ public class Ruler extends JFrame {
private
static
final
int
F_HEIGHT
=
400
;
private
static
final
int
F_WIDTH
=
(
int
)
(
F_HEIGHT
*
1.618
+
0.5
);
private
static
void
checkTranslucencyMode
(
WindowTranslucency
arg
)
{
private
static
boolean
translucencySupported
;
private
static
boolean
transparencySupported
;
private
static
boolean
checkTranslucencyMode
(
WindowTranslucency
arg
)
{
GraphicsEnvironment
ge
=
GraphicsEnvironment
.
getLocalGraphicsEnvironment
();
GraphicsDevice
gd
=
ge
.
getDefaultScreenDevice
();
if
(!
gd
.
isWindowTranslucencySupported
(
arg
))
{
System
.
err
.
println
(
"'"
+
arg
+
"' translucency mode isn't supported."
);
System
.
exit
(-
1
);
}
return
gd
.
isWindowTranslucencySupported
(
arg
);
}
private
final
ComponentAdapter
componentListener
=
new
ComponentAdapter
()
{
/**
* Applies the shape to window. It is recommended to apply shape in
* componentResized() method
*/
@Override
public
void
componentResized
(
ComponentEvent
e
)
{
public
Shape
buildShape
()
{
int
h
=
getHeight
();
int
w
=
getWidth
();
float
a
=
(
float
)
Math
.
hypot
(
h
,
w
);
...
...
@@ -109,24 +99,43 @@ public class Ruler extends JFrame {
path
.
lineTo
(
W
,
h
-
W
*
(
a
+
h
)
/
w
);
path
.
lineTo
(
w
-
W
*
(
a
+
w
)
/
h
,
W
);
path
.
closePath
();
setShape
(
path
);
return
path
;
}
private
final
ComponentAdapter
componentListener
=
new
ComponentAdapter
()
{
/**
* Applies the shape to window. It is recommended to apply shape in
* componentResized() method
*/
@Override
public
void
componentResized
(
ComponentEvent
e
)
{
// We do apply shape only if PERPIXEL_TRANSPARENT is supported
if
(
transparencySupported
)
{
setShape
(
buildShape
());
}
}
};
private
final
Action
exitAction
=
new
AbstractAction
(
"Exit"
)
{
{
putValue
(
Action
.
MNEMONIC_KEY
,
KeyEvent
.
VK_X
);
}
@Override
public
void
actionPerformed
(
ActionEvent
e
)
{
System
.
exit
(
0
);
}
};
private
final
JPopupMenu
jPopupMenu
=
new
JPopupMenu
();
{
jPopupMenu
.
add
(
new
JMenuItem
(
exitAction
));
}
/**
* Implements mouse-related behavior: window dragging and popup menu
* invocation
...
...
@@ -157,6 +166,7 @@ public class Ruler extends JFrame {
}
}
};
/**
* Implements keyboard navigation. Arrows move by 5 pixels, Ctrl + arrows
* move by 50 pixels, Alt + arrows move by 1 pixel.
...
...
@@ -201,10 +211,22 @@ public class Ruler extends JFrame {
@Override
protected
void
paintComponent
(
Graphics
g
)
{
Graphics
gg
=
g
.
create
();
Graphics
2D
gg
=
(
Graphics2D
)
g
.
create
();
int
w
=
getWidth
();
int
h
=
getHeight
();
int
hh
=
gg
.
getFontMetrics
().
getAscent
();
// This is an approach to apply shape when PERPIXEL_TRANSPARENT
// isn't supported
if
(!
transparencySupported
)
{
gg
.
setBackground
(
new
Color
(
0
,
0
,
0
,
0
));
gg
.
clearRect
(
0
,
0
,
w
,
h
);
gg
.
clip
(
buildShape
());
gg
.
setBackground
(
Ruler
.
this
.
getBackground
());
gg
.
clearRect
(
0
,
0
,
w
,
h
);
}
gg
.
setColor
(
FOREGROUND
);
for
(
int
x
=
0
;
x
<
w
*
(
h
-
8
)
/
h
-
5
;
x
+=
5
)
{
boolean
hi
=
x
%
50
==
0
;
...
...
@@ -216,6 +238,7 @@ public class Ruler extends JFrame {
gg
.
drawString
(
number
,
x
+
5
-
ww
/
2
,
20
+
hh
);
}
}
gg
.
dispose
();
}
});
...
...
@@ -231,9 +254,17 @@ public class Ruler extends JFrame {
SwingUtilities
.
invokeAndWait
(
new
Runnable
()
{
@Override
public
void
run
()
{
checkTranslucencyMode
(
WindowTranslucency
.
PERPIXEL_TRANSLUCENT
);
checkTranslucencyMode
(
WindowTranslucency
.
PERPIXEL_TRANSPARENT
);
translucencySupported
=
checkTranslucencyMode
(
PERPIXEL_TRANSLUCENT
);
transparencySupported
=
checkTranslucencyMode
(
PERPIXEL_TRANSPARENT
);
if
(!
translucencySupported
)
{
System
.
err
.
println
(
"This application requires "
+
"'PERPIXEL_TRANSLUCENT' translucency mode to "
+
"be supported."
);
System
.
exit
(-
1
);
}
Ruler
ruler
=
new
Ruler
();
ruler
.
setVisible
(
true
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录