Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
f9b20744
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看板
提交
f9b20744
编写于
5月 14, 2013
作者:
S
sundar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8014519: scriptpad sample does not work with nashorn
Reviewed-by: attila, jlaskey Contributed-by: rieberandreas@gmail.com
上级
733e7b93
变更
14
展开全部
隐藏空白更改
内联
并排
Showing
14 changed file
with
720 addition
and
671 deletion
+720
-671
src/share/sample/scripting/scriptpad/src/com/sun/sample/scriptpad/Main.java
...cripting/scriptpad/src/com/sun/sample/scriptpad/Main.java
+2
-2
src/share/sample/scripting/scriptpad/src/resources/Main.js
src/share/sample/scripting/scriptpad/src/resources/Main.js
+1
-3
src/share/sample/scripting/scriptpad/src/resources/conc.js
src/share/sample/scripting/scriptpad/src/resources/conc.js
+92
-33
src/share/sample/scripting/scriptpad/src/resources/gui.js
src/share/sample/scripting/scriptpad/src/resources/gui.js
+37
-29
src/share/sample/scripting/scriptpad/src/resources/mm.js
src/share/sample/scripting/scriptpad/src/resources/mm.js
+16
-20
src/share/sample/scripting/scriptpad/src/resources/scriptpad.js
...are/sample/scripting/scriptpad/src/resources/scriptpad.js
+512
-510
src/share/sample/scripting/scriptpad/src/scripts/browse.js
src/share/sample/scripting/scriptpad/src/scripts/browse.js
+17
-21
src/share/sample/scripting/scriptpad/src/scripts/insertfile.js
...hare/sample/scripting/scriptpad/src/scripts/insertfile.js
+7
-4
src/share/sample/scripting/scriptpad/src/scripts/linewrap.js
src/share/sample/scripting/scriptpad/src/scripts/linewrap.js
+5
-9
src/share/sample/scripting/scriptpad/src/scripts/mail.js
src/share/sample/scripting/scriptpad/src/scripts/mail.js
+15
-18
src/share/sample/scripting/scriptpad/src/scripts/memmonitor.js
...hare/sample/scripting/scriptpad/src/scripts/memmonitor.js
+9
-8
src/share/sample/scripting/scriptpad/src/scripts/memory.js
src/share/sample/scripting/scriptpad/src/scripts/memory.js
+5
-7
src/share/sample/scripting/scriptpad/src/scripts/memory.sh
src/share/sample/scripting/scriptpad/src/scripts/memory.sh
+0
-4
src/share/sample/scripting/scriptpad/src/scripts/textcolor.js
...share/sample/scripting/scriptpad/src/scripts/textcolor.js
+2
-3
未找到文件。
src/share/sample/scripting/scriptpad/src/com/sun/sample/scriptpad/Main.java
浏览文件 @
f9b20744
/*
/*
* Copyright (c) 2006, 201
1
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 201
3
, 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
...
@@ -75,7 +75,7 @@ public class Main {
...
@@ -75,7 +75,7 @@ public class Main {
*/
*/
InputStream
is
=
Main
.
class
.
getResourceAsStream
(
"/resources/"
+
name
);
InputStream
is
=
Main
.
class
.
getResourceAsStream
(
"/resources/"
+
name
);
// current script file name for better error messages
// current script file name for better error messages
engine
.
put
(
ScriptEngine
.
NAME
,
name
);
engine
.
put
(
ScriptEngine
.
FILE
NAME
,
name
);
// evaluate the script in the InputStream
// evaluate the script in the InputStream
engine
.
eval
(
new
InputStreamReader
(
is
));
engine
.
eval
(
new
InputStreamReader
(
is
));
}
}
...
...
src/share/sample/scripting/scriptpad/src/resources/Main.js
浏览文件 @
f9b20744
/*
/*
* Copyright (c) 2006, 201
1
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 201
3
, 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
...
@@ -37,7 +37,6 @@
...
@@ -37,7 +37,6 @@
* this sample code.
* this sample code.
*/
*/
/*
/*
* This script can be loaded in jrunscript to start scriptpad.
* This script can be loaded in jrunscript to start scriptpad.
*
*
...
@@ -48,4 +47,3 @@ load("conc.js");
...
@@ -48,4 +47,3 @@ load("conc.js");
load
(
"
gui.js
"
);
load
(
"
gui.js
"
);
load
(
"
scriptpad.js
"
);
load
(
"
scriptpad.js
"
);
load
(
"
mm.js
"
);
load
(
"
mm.js
"
);
src/share/sample/scripting/scriptpad/src/resources/conc.js
浏览文件 @
f9b20744
/*
/*
* Copyright (c) 2006, 201
1
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 201
3
, 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
...
@@ -37,15 +37,43 @@
...
@@ -37,15 +37,43 @@
* this sample code.
* this sample code.
*/
*/
/*
/*
* Concurrency utilities for JavaScript. These are based on
* Concurrency utilities for JavaScript. These are based on
* java.lang and java.util.concurrent API. The following functions
* java.lang and java.util.concurrent API. The following functions
* provide a simpler API for scripts. Instead of directly using java.lang
* provide a simpler API for scripts. Instead of directly using java.lang
* and java.util.concurrent classes, scripts can use functions and
* and java.util.concurrent classes, scripts can use functions and
* objects exported from here.
* objects exported from here.
*/
*/
// shortcut for j.u.c lock classes
var
Lock
=
java
.
util
.
concurrent
.
locks
.
ReentrantLock
;
var
RWLock
=
java
.
util
.
concurrent
.
locks
.
ReentrantReadWriteLock
;
// check if there is a build in sync function, define one if missing
if
(
typeof
sync
===
"
undefined
"
)
{
var
sync
=
function
(
func
,
obj
)
{
if
(
arguments
.
length
<
1
||
arguments
.
length
>
2
)
{
throw
"
sync(function [,object]) parameter count mismatch
"
;
}
var
syncobj
=
(
arguments
.
length
==
2
?
obj
:
this
);
if
(
!
syncobj
.
_syncLock
)
{
syncobj
.
_syncLock
=
new
Lock
();
}
return
function
()
{
syncobj
.
_syncLock
.
lock
();
try
{
func
.
apply
(
null
,
arguments
);
}
finally
{
syncobj
.
_syncLock
.
unlock
();
}
};
};
sync
.
docString
=
"
synchronize a function, optionally on an object
"
;
}
/**
/**
* Wrapper for java.lang.Object.wait
* Wrapper for java.lang.Object.wait
*
*
...
@@ -58,7 +86,6 @@ function wait(object) {
...
@@ -58,7 +86,6 @@ function wait(object) {
}
}
wait
.
docString
=
"
convenient wrapper for java.lang.Object.wait method
"
;
wait
.
docString
=
"
convenient wrapper for java.lang.Object.wait method
"
;
/**
/**
* Wrapper for java.lang.Object.notify
* Wrapper for java.lang.Object.notify
*
*
...
@@ -71,7 +98,6 @@ function notify(object) {
...
@@ -71,7 +98,6 @@ function notify(object) {
}
}
notify
.
docString
=
"
convenient wrapper for java.lang.Object.notify method
"
;
notify
.
docString
=
"
convenient wrapper for java.lang.Object.notify method
"
;
/**
/**
* Wrapper for java.lang.Object.notifyAll
* Wrapper for java.lang.Object.notifyAll
*
*
...
@@ -84,7 +110,6 @@ function notifyAll(object) {
...
@@ -84,7 +110,6 @@ function notifyAll(object) {
}
}
notifyAll
.
docString
=
"
convenient wrapper for java.lang.Object.notifyAll method
"
;
notifyAll
.
docString
=
"
convenient wrapper for java.lang.Object.notifyAll method
"
;
/**
/**
* Creates a java.lang.Runnable from a given script
* Creates a java.lang.Runnable from a given script
* function.
* function.
...
@@ -97,7 +122,7 @@ Function.prototype.runnable = function() {
...
@@ -97,7 +122,7 @@ Function.prototype.runnable = function() {
func
.
apply
(
null
,
args
);
func
.
apply
(
null
,
args
);
}
}
}
}
}
}
;
/**
/**
* Executes the function on a new Java Thread.
* Executes the function on a new Java Thread.
...
@@ -106,7 +131,7 @@ Function.prototype.thread = function() {
...
@@ -106,7 +131,7 @@ Function.prototype.thread = function() {
var
t
=
new
java
.
lang
.
Thread
(
this
.
runnable
.
apply
(
this
,
arguments
));
var
t
=
new
java
.
lang
.
Thread
(
this
.
runnable
.
apply
(
this
,
arguments
));
t
.
start
();
t
.
start
();
return
t
;
return
t
;
}
}
;
/**
/**
* Executes the function on a new Java daemon Thread.
* Executes the function on a new Java daemon Thread.
...
@@ -116,7 +141,7 @@ Function.prototype.daemon = function() {
...
@@ -116,7 +141,7 @@ Function.prototype.daemon = function() {
t
.
setDaemon
(
true
);
t
.
setDaemon
(
true
);
t
.
start
();
t
.
start
();
return
t
;
return
t
;
}
}
;
/**
/**
* Creates a java.util.concurrent.Callable from a given script
* Creates a java.util.concurrent.Callable from a given script
...
@@ -128,7 +153,7 @@ Function.prototype.callable = function() {
...
@@ -128,7 +153,7 @@ Function.prototype.callable = function() {
return
new
java
.
util
.
concurrent
.
Callable
()
{
return
new
java
.
util
.
concurrent
.
Callable
()
{
call
:
function
()
{
return
func
.
apply
(
null
,
args
);
}
call
:
function
()
{
return
func
.
apply
(
null
,
args
);
}
}
}
}
}
;
/**
/**
* Registers the script function so that it will be called exit.
* Registers the script function so that it will be called exit.
...
@@ -137,10 +162,10 @@ Function.prototype.atexit = function () {
...
@@ -137,10 +162,10 @@ Function.prototype.atexit = function () {
var
args
=
arguments
;
var
args
=
arguments
;
java
.
lang
.
Runtime
.
getRuntime
().
addShutdownHook
(
java
.
lang
.
Runtime
.
getRuntime
().
addShutdownHook
(
new
java
.
lang
.
Thread
(
this
.
runnable
.
apply
(
this
,
args
)));
new
java
.
lang
.
Thread
(
this
.
runnable
.
apply
(
this
,
args
)));
}
}
;
/**
/**
* Executes the function asynchronously.
* Executes the function asynchronously.
*
*
* @return a java.util.concurrent.FutureTask
* @return a java.util.concurrent.FutureTask
*/
*/
...
@@ -152,13 +177,9 @@ Function.prototype.future = (function() {
...
@@ -152,13 +177,9 @@ Function.prototype.future = (function() {
(
function
()
{
theExecutor
.
shutdown
();
}).
atexit
();
(
function
()
{
theExecutor
.
shutdown
();
}).
atexit
();
return
function
()
{
return
function
()
{
return
theExecutor
.
submit
(
this
.
callable
.
apply
(
this
,
arguments
));
return
theExecutor
.
submit
(
this
.
callable
.
apply
(
this
,
arguments
));
}
}
;
})();
})();
// shortcut for j.u.c lock classes
var
Lock
=
java
.
util
.
concurrent
.
locks
.
ReentrantLock
;
var
RWLock
=
java
.
util
.
concurrent
.
locks
.
ReentrantReadWriteLock
;
/**
/**
* Executes a function after acquiring given lock. On return,
* Executes a function after acquiring given lock. On return,
* (normal or exceptional), lock is released.
* (normal or exceptional), lock is released.
...
@@ -179,7 +200,7 @@ Function.prototype.sync = function (lock) {
...
@@ -179,7 +200,7 @@ Function.prototype.sync = function (lock) {
}
finally
{
}
finally
{
lock
.
unlock
();
lock
.
unlock
();
}
}
}
}
;
/**
/**
* Causes current thread to sleep for specified
* Causes current thread to sleep for specified
...
@@ -193,54 +214,92 @@ function sleep(interval) {
...
@@ -193,54 +214,92 @@ function sleep(interval) {
sleep
.
docString
=
"
wrapper for java.lang.Thread.sleep method
"
;
sleep
.
docString
=
"
wrapper for java.lang.Thread.sleep method
"
;
/**
/**
* Schedules a task to be executed once in
* Schedules a task to be executed once in N milliseconds specified.
* every N milliseconds specified.
*
*
* @param callback function or expression to evaluate
* @param callback function or expression to evaluate
* @param interval in milliseconds to sleep
* @param interval in milliseconds to sleep
* @return timeout ID (which is nothing but Thread instance)
* @return timeout ID (which is nothing but Thread instance)
*/
*/
function
setTimeout
(
callback
,
interval
)
{
function
setTimeout
(
callback
,
interval
)
{
if
(
!
(
callback
instanceof
Function
))
{
if
(
!
(
callback
instanceof
Function
)
&&
typeof
callback
!==
"
function
"
)
{
callback
=
new
Function
(
callback
);
callback
=
new
Function
(
callback
);
}
}
// start a new thread that sleeps given time
// start a new thread that sleeps given time
// and calls callback in an infinite loop
// and calls callback in an infinite loop
return
(
function
()
{
return
(
function
()
{
while
(
true
)
{
try
{
sleep
(
interval
);
sleep
(
interval
);
}
catch
(
x
)
{
}
callback
();
}).
daemon
();
}
setTimeout
.
docString
=
"
calls given callback once after specified interval
"
;
/**
* Cancels a timeout set earlier.
* @param tid timeout ID returned from setTimeout
*/
function
clearTimeout
(
tid
)
{
// we just interrupt the timer thread
tid
.
interrupt
();
}
clearTimeout
.
docString
=
"
interrupt a setTimeout timer
"
;
/**
* Schedules a task to be executed once in
* every N milliseconds specified.
*
* @param callback function or expression to evaluate
* @param interval in milliseconds to sleep
* @return timeout ID (which is nothing but Thread instance)
*/
function
setInterval
(
callback
,
interval
)
{
if
(
!
(
callback
instanceof
Function
)
&&
typeof
callback
!==
"
function
"
)
{
callback
=
new
Function
(
callback
);
}
// start a new thread that sleeps given time
// and calls callback in an infinite loop
return
(
function
()
{
while
(
true
)
{
try
{
sleep
(
interval
);
}
catch
(
x
)
{
break
;
}
callback
();
callback
();
}
}
}).
daemon
();
}).
daemon
();
}
}
set
Timeout
.
docString
=
"
calls given callback once after specified interval
"
set
Interval
.
docString
=
"
calls given callback every specified interval
"
;
/**
/**
* Cancels a timeout set earlier.
* Cancels a timeout set earlier.
* @param tid timeout ID returned from setTimeout
* @param tid timeout ID returned from setTimeout
*/
*/
function
clear
Timeout
(
tid
)
{
function
clear
Interval
(
tid
)
{
// we just interrupt the timer thread
// we just interrupt the timer thread
tid
.
interrupt
();
tid
.
interrupt
();
}
}
clearInterval
.
docString
=
"
interrupt a setInterval timer
"
;
/**
/**
* Simple access to thread local storage.
* Simple access to thread local storage.
*
*
* Script sample:
* Script sample:
*
*
* __thread.x = 44;
* __thread.x = 44;
* function f() {
* function f() {
* __thread.x = 'hello';
* __thread.x = 'hello';
* print(__thread.x);
* print(__thread.x);
* }
* }
* f.thread(); // prints 'hello'
* f.thread(); // prints 'hello'
* print(__thread.x); // prints 44 in main thread
* print(__thread.x); // prints 44 in main thread
*/
*/
var
__thread
=
(
function
()
{
var
__thread
=
(
function
()
{
var
map
=
new
Object
();
var
map
=
new
Object
();
return
new
JSAdapter
(
)
{
return
new
JSAdapter
({
__has__
:
function
(
name
)
{
__has__
:
function
(
name
)
{
return
map
[
name
]
!=
undefined
;
return
map
[
name
]
!=
undefined
;
},
},
...
@@ -263,8 +322,8 @@ var __thread = (function () {
...
@@ -263,8 +322,8 @@ var __thread = (function () {
__delete__
:
function
(
name
)
{
__delete__
:
function
(
name
)
{
if
(
map
[
name
]
!=
undefined
)
{
if
(
map
[
name
]
!=
undefined
)
{
map
[
name
].
set
(
null
);
map
[
name
].
set
(
null
);
}
}
}
}
}
}
);
})();
})();
src/share/sample/scripting/scriptpad/src/resources/gui.js
浏览文件 @
f9b20744
/*
/*
* Copyright (c) 2006, 201
1
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 201
3
, 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
...
@@ -37,16 +37,15 @@
...
@@ -37,16 +37,15 @@
* this sample code.
* this sample code.
*/
*/
/*
/*
* Few user interface utilities.
* Few user interface utilities.
*/
*/
if
(
this
.
window
===
undefined
)
{
if
(
this
.
window
===
undefined
)
{
this
.
window
=
null
;
this
.
window
=
null
;
}
}
/**
/**
* Swing invokeLater - invokes given function in AWT event thread
* Swing invokeLater - invokes given function in AWT event thread
*/
*/
Function
.
prototype
.
invokeLater
=
function
()
{
Function
.
prototype
.
invokeLater
=
function
()
{
...
@@ -54,13 +53,13 @@ Function.prototype.invokeLater = function() {
...
@@ -54,13 +53,13 @@ Function.prototype.invokeLater = function() {
var
func
=
this
;
var
func
=
this
;
var
args
=
arguments
;
var
args
=
arguments
;
SwingUtilities
.
invokeLater
(
new
java
.
lang
.
Runnable
()
{
SwingUtilities
.
invokeLater
(
new
java
.
lang
.
Runnable
()
{
run
:
function
()
{
run
:
function
()
{
func
.
apply
(
func
,
args
);
func
.
apply
(
func
,
args
);
}
}
});
});
}
}
;
/**
/**
* Swing invokeAndWait - invokes given function in AWT event thread
* Swing invokeAndWait - invokes given function in AWT event thread
* and waits for it's completion
* and waits for it's completion
*/
*/
...
@@ -69,11 +68,11 @@ Function.prototype.invokeAndWait = function() {
...
@@ -69,11 +68,11 @@ Function.prototype.invokeAndWait = function() {
var
func
=
this
;
var
func
=
this
;
var
args
=
arguments
;
var
args
=
arguments
;
SwingUtilities
.
invokeAndWait
(
new
java
.
lang
.
Runnable
()
{
SwingUtilities
.
invokeAndWait
(
new
java
.
lang
.
Runnable
()
{
run
:
function
()
{
run
:
function
()
{
func
.
apply
(
func
,
args
);
func
.
apply
(
func
,
args
);
}
}
});
});
}
}
;
/**
/**
* Am I running in AWT event dispatcher thread?
* Am I running in AWT event dispatcher thread?
...
@@ -85,22 +84,24 @@ function isEventThread() {
...
@@ -85,22 +84,24 @@ function isEventThread() {
isEventThread
.
docString
=
"
returns whether the current thread is GUI thread
"
;
isEventThread
.
docString
=
"
returns whether the current thread is GUI thread
"
;
/**
/**
* Opens a file dialog box
* Opens a file dialog box
*
*
* @param curDir current directory [optional]
* @param curDir current directory [optional]
* @param save flag tells whether this is a save dialog or not
* @param save flag tells whether this is a save dialog or not
* @return selected file or else null
* @return selected file or else null
*/
*/
function
fileDialog
(
curDir
,
save
)
{
function
fileDialog
(
curDir
,
save
)
{
var
result
;
var
result
;
function
_fileDialog
()
{
function
_fileDialog
()
{
if
(
curDir
==
undefined
)
{
if
(
curDir
==
undefined
)
{
curDir
=
new
java
.
io
.
File
(
"
.
"
);
curDir
=
new
java
.
io
.
File
(
"
.
"
);
}
}
var
JFileChooser
=
javax
.
swing
.
JFileChooser
;
var
JFileChooser
=
javax
.
swing
.
JFileChooser
;
var
dialog
=
new
JFileChooser
(
curDir
);
var
dialog
=
new
JFileChooser
(
curDir
);
var
res
=
save
?
dialog
.
showSaveDialog
(
window
):
var
res
=
save
?
dialog
.
showSaveDialog
(
window
):
dialog
.
showOpenDialog
(
window
);
dialog
.
showOpenDialog
(
window
);
if
(
res
==
JFileChooser
.
APPROVE_OPTION
)
{
if
(
res
==
JFileChooser
.
APPROVE_OPTION
)
{
result
=
dialog
.
getSelectedFile
();
result
=
dialog
.
getSelectedFile
();
}
else
{
}
else
{
...
@@ -113,37 +114,41 @@ function fileDialog(curDir, save) {
...
@@ -113,37 +114,41 @@ function fileDialog(curDir, save) {
}
else
{
}
else
{
_fileDialog
.
invokeAndWait
();
_fileDialog
.
invokeAndWait
();
}
}
return
result
;
return
result
;
}
}
fileDialog
.
docString
=
"
show a file dialog box
"
;
fileDialog
.
docString
=
"
show a file dialog box
"
;
/**
/**
* Opens a color chooser dialog box
* Opens a color chooser dialog box
*
*
* @param title of the dialog box [optional]
* @param title of the dialog box [optional]
* @param color default color [optional]
* @param color default color [optional]
* @return choosen color or default color
* @return choosen color or default color
*/
*/
function
colorDialog
(
title
,
color
)
{
function
colorDialog
(
title
,
color
)
{
var
result
;
var
result
;
function
_colorDialog
()
{
function
_colorDialog
()
{
if
(
title
==
undefined
)
{
if
(
title
==
undefined
)
{
title
=
"
Choose Color
"
;
title
=
"
Choose Color
"
;
}
}
if
(
color
==
undefined
)
{
if
(
color
==
undefined
)
{
color
=
java
.
awt
.
Color
.
BLACK
;
color
=
java
.
awt
.
Color
.
BLACK
;
}
}
var
chooser
=
new
javax
.
swing
.
JColorChooser
();
var
chooser
=
new
javax
.
swing
.
JColorChooser
();
var
res
=
chooser
.
showDialog
(
window
,
title
,
color
);
var
res
=
chooser
.
showDialog
(
window
,
title
,
color
);
result
=
res
?
res
:
color
;
result
=
res
?
res
:
color
;
}
}
if
(
isEventThread
())
{
if
(
isEventThread
())
{
_colorDialog
();
_colorDialog
();
}
else
{
}
else
{
_colorDialog
.
invokeAndWait
();
_colorDialog
.
invokeAndWait
();
}
}
return
result
;
return
result
;
}
}
colorDialog
.
docString
=
"
shows a color chooser dialog box
"
;
colorDialog
.
docString
=
"
shows a color chooser dialog box
"
;
...
@@ -156,15 +161,15 @@ colorDialog.docString = "shows a color chooser dialog box";
...
@@ -156,15 +161,15 @@ colorDialog.docString = "shows a color chooser dialog box";
* @param msgType type of message box [constants in JOptionPane]
* @param msgType type of message box [constants in JOptionPane]
*/
*/
function
msgBox
(
msg
,
title
,
msgType
)
{
function
msgBox
(
msg
,
title
,
msgType
)
{
function
_msgBox
()
{
function
_msgBox
()
{
var
JOptionPane
=
javax
.
swing
.
JOptionPane
;
var
JOptionPane
=
javax
.
swing
.
JOptionPane
;
if
(
msg
===
undefined
)
msg
=
"
undefined
"
;
if
(
msg
===
undefined
)
msg
=
"
undefined
"
;
if
(
msg
===
null
)
msg
=
"
null
"
;
if
(
msg
===
null
)
msg
=
"
null
"
;
if
(
title
==
undefined
)
title
=
msg
;
if
(
title
==
undefined
)
title
=
msg
;
if
(
msgType
==
undefined
)
t
ype
=
JOptionPane
.
INFORMATION_MESSAGE
;
if
(
msgType
==
undefined
)
msgT
ype
=
JOptionPane
.
INFORMATION_MESSAGE
;
JOptionPane
.
showMessageDialog
(
window
,
msg
,
title
,
msgType
);
JOptionPane
.
showMessageDialog
(
window
,
msg
,
title
,
msgType
);
}
}
if
(
isEventThread
())
{
if
(
isEventThread
())
{
_msgBox
();
_msgBox
();
}
else
{
}
else
{
...
@@ -172,13 +177,13 @@ function msgBox(msg, title, msgType) {
...
@@ -172,13 +177,13 @@ function msgBox(msg, title, msgType) {
}
}
}
}
msgBox
.
docString
=
"
shows MessageBox to the user
"
;
msgBox
.
docString
=
"
shows MessageBox to the user
"
;
/**
/**
* Shows an information alert box
* Shows an information alert box
*
*
* @param msg message to be shown
* @param msg message to be shown
* @param title title of message box [optional]
* @param title title of message box [optional]
*/
*/
function
alert
(
msg
,
title
)
{
function
alert
(
msg
,
title
)
{
var
JOptionPane
=
javax
.
swing
.
JOptionPane
;
var
JOptionPane
=
javax
.
swing
.
JOptionPane
;
msgBox
(
msg
,
title
,
JOptionPane
.
INFORMATION_MESSAGE
);
msgBox
(
msg
,
title
,
JOptionPane
.
INFORMATION_MESSAGE
);
...
@@ -197,7 +202,6 @@ function error(msg, title) {
...
@@ -197,7 +202,6 @@ function error(msg, title) {
}
}
error
.
docString
=
"
shows an error message box to the user
"
;
error
.
docString
=
"
shows an error message box to the user
"
;
/**
/**
* Shows a warning alert box
* Shows a warning alert box
*
*
...
@@ -210,7 +214,6 @@ function warn(msg, title) {
...
@@ -210,7 +214,6 @@ function warn(msg, title) {
}
}
warn
.
docString
=
"
shows a warning message box to the user
"
;
warn
.
docString
=
"
shows a warning message box to the user
"
;
/**
/**
* Shows a prompt dialog box
* Shows a prompt dialog box
*
*
...
@@ -225,11 +228,13 @@ function prompt(question, answer) {
...
@@ -225,11 +228,13 @@ function prompt(question, answer) {
if
(
answer
==
undefined
)
answer
=
""
;
if
(
answer
==
undefined
)
answer
=
""
;
result
=
JOptionPane
.
showInputDialog
(
window
,
question
,
answer
);
result
=
JOptionPane
.
showInputDialog
(
window
,
question
,
answer
);
}
}
if
(
isEventThread
())
{
if
(
isEventThread
())
{
_prompt
();
_prompt
();
}
else
{
}
else
{
_prompt
.
invokeAndWait
();
_prompt
.
invokeAndWait
();
}
}
return
result
;
return
result
;
}
}
prompt
.
docString
=
"
shows a prompt box to the user and returns the answer
"
;
prompt
.
docString
=
"
shows a prompt box to the user and returns the answer
"
;
...
@@ -244,30 +249,33 @@ prompt.docString = "shows a prompt box to the user and returns the answer";
...
@@ -244,30 +249,33 @@ prompt.docString = "shows a prompt box to the user and returns the answer";
function
confirm
(
msg
,
title
)
{
function
confirm
(
msg
,
title
)
{
var
result
;
var
result
;
var
JOptionPane
=
javax
.
swing
.
JOptionPane
;
var
JOptionPane
=
javax
.
swing
.
JOptionPane
;
function
_confirm
()
{
function
_confirm
()
{
if
(
title
==
undefined
)
title
=
msg
;
if
(
title
==
undefined
)
title
=
msg
;
var
optionType
=
JOptionPane
.
YES_NO_OPTION
;
var
optionType
=
JOptionPane
.
YES_NO_OPTION
;
result
=
JOptionPane
.
showConfirmDialog
(
window
,
msg
,
title
,
optionType
);
result
=
JOptionPane
.
showConfirmDialog
(
window
,
msg
,
title
,
optionType
);
}
}
if
(
isEventThread
())
{
if
(
isEventThread
())
{
_confirm
();
_confirm
();
}
else
{
}
else
{
_confirm
.
invokeAndWait
();
_confirm
.
invokeAndWait
();
}
}
return
result
==
JOptionPane
.
YES_OPTION
;
return
result
==
JOptionPane
.
YES_OPTION
;
}
}
confirm
.
docString
=
"
shows a confirmation message box to the user
"
;
confirm
.
docString
=
"
shows a confirmation message box to the user
"
;
/**
/**
* Exit the process after confirmation from user
* Exit the process after confirmation from user
*
*
* @param exitCode return code to OS [optional]
* @param exitCode return code to OS [optional]
*/
*/
function
exit
(
exitCode
)
{
function
exit
(
exitCode
)
{
if
(
exitCode
==
undefined
)
exitCode
=
0
;
if
(
exitCode
==
undefined
)
exitCode
=
0
;
if
(
confirm
(
"
Do you really want to exit?
"
))
{
if
(
confirm
(
"
Do you really want to exit?
"
))
{
java
.
lang
.
System
.
exit
(
exitCode
);
java
.
lang
.
System
.
exit
(
exitCode
);
}
}
}
}
exit
.
docString
=
"
exits jconsole
"
;
exit
.
docString
=
"
exits jconsole
"
;
...
...
src/share/sample/scripting/scriptpad/src/resources/mm.js
浏览文件 @
f9b20744
/*
/*
* Copyright (c) 2006, 201
1
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 201
3
, 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
...
@@ -37,10 +37,9 @@
...
@@ -37,10 +37,9 @@
* this sample code.
* this sample code.
*/
*/
/*
/*
* This is a collection of utilities for Monitoring
* This is a collection of utilities for Monitoring
* and management API.
* and management API.
*
*
* File dependency:
* File dependency:
* conc.js -> for concurrency utilities
* conc.js -> for concurrency utilities
...
@@ -71,14 +70,14 @@ function jmxConnect(hostport) {
...
@@ -71,14 +70,14 @@ function jmxConnect(hostport) {
}
}
jmxConnect
.
docString
=
"
connects to the given host, port (specified as name:port)
"
;
jmxConnect
.
docString
=
"
connects to the given host, port (specified as name:port)
"
;
function
mbeanConnection
()
{
function
mbeanConnection
()
{
if
(
mmConnection
==
null
)
{
if
(
mmConnection
==
null
)
{
throw
"
Not connected to MBeanServer yet!
"
;
throw
"
Not connected to MBeanServer yet!
"
;
}
}
return
mmConnection
;
return
mmConnection
;
}
}
mbeanConnection
.
docString
=
"
returns the current MBeanServer connection
"
mbeanConnection
.
docString
=
"
returns the current MBeanServer connection
"
;
/**
/**
* Returns a platform MXBean proxy for given MXBean name and interface class
* Returns a platform MXBean proxy for given MXBean name and interface class
...
@@ -102,7 +101,6 @@ function objectName(objName) {
...
@@ -102,7 +101,6 @@ function objectName(objName) {
}
}
objectName
.
docString
=
"
creates JMX ObjectName for a given String
"
;
objectName
.
docString
=
"
creates JMX ObjectName for a given String
"
;
/**
/**
* Creates a new (M&M) Attribute object
* Creates a new (M&M) Attribute object
*
*
...
@@ -146,7 +144,6 @@ function queryNames(objName, query) {
...
@@ -146,7 +144,6 @@ function queryNames(objName, query) {
}
}
queryNames
.
docString
=
"
returns QueryNames using given ObjectName and optional query
"
;
queryNames
.
docString
=
"
returns QueryNames using given ObjectName and optional query
"
;
/**
/**
* Queries with given ObjectName and QueryExp.
* Queries with given ObjectName and QueryExp.
* QueryExp may be null.
* QueryExp may be null.
...
@@ -220,7 +217,6 @@ function getMBeanAttribute(objName, attrName) {
...
@@ -220,7 +217,6 @@ function getMBeanAttribute(objName, attrName) {
}
}
getMBeanAttribute
.
docString
=
"
returns a single Attribute of given ObjectName
"
;
getMBeanAttribute
.
docString
=
"
returns a single Attribute of given ObjectName
"
;
// sets MBean attributes
// sets MBean attributes
function
setMBeanAttributes
(
objName
,
attrList
)
{
function
setMBeanAttributes
(
objName
,
attrList
)
{
objName
=
objectName
(
objName
);
objName
=
objectName
(
objName
);
...
@@ -237,7 +233,6 @@ function setMBeanAttribute(objName, attrName, attrValue) {
...
@@ -237,7 +233,6 @@ function setMBeanAttribute(objName, attrName, attrValue) {
}
}
setMBeanAttribute
.
docString
=
"
sets a single Attribute of given ObjectName
"
;
setMBeanAttribute
.
docString
=
"
sets a single Attribute of given ObjectName
"
;
// invokes an operation on given MBean
// invokes an operation on given MBean
function
invokeMBean
(
objName
,
operation
,
params
,
signature
)
{
function
invokeMBean
(
objName
,
operation
,
params
,
signature
)
{
objName
=
objectName
(
objName
);
objName
=
objectName
(
objName
);
...
@@ -260,16 +255,17 @@ invokeMBean.docString = "invokes MBean operation on given ObjectName";
...
@@ -260,16 +255,17 @@ invokeMBean.docString = "invokes MBean operation on given ObjectName";
* will be of type FutureTask. When you need value, call 'get' on it.
* will be of type FutureTask. When you need value, call 'get' on it.
*/
*/
function
mbean
(
objName
,
async
)
{
function
mbean
(
objName
,
async
)
{
var
index
;
objName
=
objectName
(
objName
);
objName
=
objectName
(
objName
);
var
info
=
mbeanInfo
(
objName
);
var
info
=
mbeanInfo
(
objName
);
var
attrs
=
info
.
attributes
;
var
attrs
=
info
.
attributes
;
var
attrMap
=
new
Object
;
var
attrMap
=
new
Object
;
for
(
var
index
in
attrs
)
{
for
(
index
in
attrs
)
{
attrMap
[
attrs
[
index
].
name
]
=
attrs
[
index
];
attrMap
[
attrs
[
index
].
name
]
=
attrs
[
index
];
}
}
var
opers
=
info
.
operations
;
var
opers
=
info
.
operations
;
var
operMap
=
new
Object
;
var
operMap
=
new
Object
;
for
(
var
index
in
opers
)
{
for
(
index
in
opers
)
{
operMap
[
opers
[
index
].
name
]
=
opers
[
index
];
operMap
[
opers
[
index
].
name
]
=
opers
[
index
];
}
}
...
@@ -288,9 +284,9 @@ function mbean(objName, async) {
...
@@ -288,9 +284,9 @@ function mbean(objName, async) {
__get__
:
function
(
name
)
{
__get__
:
function
(
name
)
{
if
(
isAttribute
(
name
))
{
if
(
isAttribute
(
name
))
{
if
(
async
)
{
if
(
async
)
{
return
getMBeanAttribute
.
future
(
objName
,
name
);
return
getMBeanAttribute
.
future
(
objName
,
name
);
}
else
{
}
else
{
return
getMBeanAttribute
(
objName
,
name
);
return
getMBeanAttribute
(
objName
,
name
);
}
}
}
else
if
(
isOperation
(
name
))
{
}
else
if
(
isOperation
(
name
))
{
var
oper
=
operMap
[
name
];
var
oper
=
operMap
[
name
];
...
@@ -302,12 +298,12 @@ function mbean(objName, async) {
...
@@ -302,12 +298,12 @@ function mbean(objName, async) {
sigNames
[
index
]
=
sigs
[
index
].
getType
();
sigNames
[
index
]
=
sigs
[
index
].
getType
();
}
}
if
(
async
)
{
if
(
async
)
{
return
invokeMBean
.
future
(
objName
,
name
,
return
invokeMBean
.
future
(
objName
,
name
,
params
,
sigNames
);
params
,
sigNames
);
}
else
{
}
else
{
return
invokeMBean
(
objName
,
name
,
params
,
sigNames
);
return
invokeMBean
(
objName
,
name
,
params
,
sigNames
);
}
}
}
}
;
}
else
{
}
else
{
return
undefined
;
return
undefined
;
}
}
...
@@ -327,9 +323,9 @@ function mbean(objName, async) {
...
@@ -327,9 +323,9 @@ function mbean(objName, async) {
}
}
mbean
.
docString
=
"
returns a conveninent script wrapper for a MBean of given ObjectName
"
;
mbean
.
docString
=
"
returns a conveninent script wrapper for a MBean of given ObjectName
"
;
if
(
this
.
application
!=
undefined
)
{
if
(
this
.
application
!=
undefined
)
{
this
.
application
.
addTool
(
"
JMX Connect
"
,
this
.
application
.
addTool
(
"
JMX Connect
"
,
// connect to a JMX MBean Server
// connect to a JMX MBean Server
function
()
{
function
()
{
var
url
=
prompt
(
"
Connect to JMX server (host:port)
"
);
var
url
=
prompt
(
"
Connect to JMX server (host:port)
"
);
if
(
url
!=
null
)
{
if
(
url
!=
null
)
{
...
...
src/share/sample/scripting/scriptpad/src/resources/scriptpad.js
浏览文件 @
f9b20744
此差异已折叠。
点击以展开。
src/share/sample/scripting/scriptpad/src/scripts/browse.js
浏览文件 @
f9b20744
/*
/*
* Copyright (c) 2006, 201
1
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 201
3
, 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
...
@@ -37,33 +37,30 @@
...
@@ -37,33 +37,30 @@
* this sample code.
* this sample code.
*/
*/
/*
/*
* This function uses new Swing Desktop API in JDK 6.
* This function uses new Swing Desktop API in JDK 6.
* To use this with scriptpad, open this in scriptpad
* To use this with scriptpad, open this in scriptpad
* and use "Tools->Run Script" menu.
* and use "Tools->Run Script" menu.
*/
*/
function
browse
()
{
function
browse
()
{
with
(
guiPkgs
)
{
var
desktop
=
null
;
var
desktop
=
null
;
// Before more Desktop API is used, first check
// Before more Desktop API is used, first check
// whether the API is supported by this particular
// whether the API is supported by this particular
// virtual machine (VM) on this particular host.
// virtual machine (VM) on this particular host.
if
(
java
.
awt
.
Desktop
.
isDesktopSupported
())
{
if
(
Desktop
.
isDesktopSupported
())
{
desktop
=
java
.
awt
.
Desktop
.
getDesktop
();
desktop
=
Desktop
.
getDesktop
();
}
else
{
}
else
{
alert
(
"
no desktop support
"
);
alert
(
"
no desktop support
"
);
return
;
return
;
}
}
if
(
desktop
.
isSupported
(
Desktop
.
Action
.
BROWSE
))
{
if
(
desktop
.
isSupported
(
java
.
awt
.
Desktop
.
Action
.
BROWSE
))
{
var
url
=
prompt
(
"
Address:
"
);
var
url
=
prompt
(
"
Address:
"
);
if
(
url
!=
null
)
{
if
(
url
!=
null
)
{
desktop
.
browse
(
new
java
.
net
.
URI
(
url
));
desktop
.
browse
(
new
java
.
net
.
URI
(
url
));
}
}
else
{
alert
(
"
no browser support
"
);
}
}
}
else
{
alert
(
"
no browser support
"
);
}
}
}
}
...
@@ -71,4 +68,3 @@ if (this.application != undefined) {
...
@@ -71,4 +68,3 @@ if (this.application != undefined) {
// add "Browse" menu item under "Tools" menu
// add "Browse" menu item under "Tools" menu
this
.
application
.
addTool
(
"
Browse
"
,
browse
);
this
.
application
.
addTool
(
"
Browse
"
,
browse
);
}
}
src/share/sample/scripting/scriptpad/src/scripts/insertfile.js
浏览文件 @
f9b20744
/*
/*
* Copyright (c) 2006, 201
1
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 201
3
, 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
...
@@ -37,7 +37,6 @@
...
@@ -37,7 +37,6 @@
* this sample code.
* this sample code.
*/
*/
/*
/*
* This script adds "Insert File" mode menu item to "Tools" menu.
* This script adds "Insert File" mode menu item to "Tools" menu.
* When selected, this menu shows a file dialog box and inserts
* When selected, this menu shows a file dialog box and inserts
...
@@ -48,18 +47,22 @@ if (this.application) {
...
@@ -48,18 +47,22 @@ if (this.application) {
application
.
addTool
(
"
Insert File...
"
,
application
.
addTool
(
"
Insert File...
"
,
function
()
{
function
()
{
var
file
=
fileDialog
();
var
file
=
fileDialog
();
if
(
file
)
{
if
(
file
)
{
var
reader
=
new
java
.
io
.
FileReader
(
file
);
var
reader
=
new
java
.
io
.
FileReader
(
file
);
var
arr
=
java
.
lang
.
reflect
.
Array
.
newInstance
(
var
arr
=
java
.
lang
.
reflect
.
Array
.
newInstance
(
java
.
lang
.
Character
.
TYPE
,
8
*
1024
);
// 8K at a time
java
.
lang
.
Character
.
TYPE
,
8
*
1024
);
// 8K at a time
var
buf
=
new
java
.
lang
.
StringBuffer
();
var
buf
=
new
java
.
lang
.
StringBuffer
();
var
numChars
;
var
numChars
;
while
((
numChars
=
reader
.
read
(
arr
,
0
,
arr
.
length
))
>
0
)
{
while
((
numChars
=
reader
.
read
(
arr
,
0
,
arr
.
length
))
>
0
)
{
buf
.
append
(
arr
,
0
,
numChars
);
buf
.
append
(
arr
,
0
,
numChars
);
}
}
var
pos
=
application
.
editor
.
caretPosition
;
var
pos
=
application
.
editor
.
caretPosition
;
var
doc
=
application
.
editor
.
document
;
var
doc
=
application
.
editor
.
document
;
doc
.
insertString
(
pos
,
buf
.
toString
(),
null
);
doc
.
insertString
(
pos
,
buf
.
toString
(),
null
);
}
}
})
})
;
}
}
src/share/sample/scripting/scriptpad/src/scripts/linewrap.js
浏览文件 @
f9b20744
/*
/*
* Copyright (c) 2006, 201
1
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 201
3
, 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
...
@@ -37,19 +37,15 @@
...
@@ -37,19 +37,15 @@
* this sample code.
* this sample code.
*/
*/
/*
/*
* This script adds "Line Wrap" mode menu item to "Tools" menu.
* This script adds "Line Wrap" mode menu item to "Tools" menu.
* When selected, this menu toggles the current word wrap mode
* When selected, this menu toggles the current word wrap mode
* of the editor.
* of the editor.
*/
*/
with
(
guiPkgs
)
{
function
toggleLineWrap
()
{
var
wrap
=
application
.
editor
.
lineWrap
;
application
.
editor
.
lineWrap
=
!
wrap
;
}
application
.
addTool
(
"
Line Wrap
"
,
toggleLineWrap
);
function
toggleLineWrap
()
{
var
wrap
=
application
.
editor
.
lineWrap
;
application
.
editor
.
lineWrap
=
!
wrap
;
}
}
application
.
addTool
(
"
Line Wrap
"
,
toggleLineWrap
);
src/share/sample/scripting/scriptpad/src/scripts/mail.js
浏览文件 @
f9b20744
/*
/*
* Copyright (c) 2006, 201
1
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 201
3
, 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
...
@@ -37,30 +37,27 @@
...
@@ -37,30 +37,27 @@
* this sample code.
* this sample code.
*/
*/
/*
/*
* This function uses new Swing Desktop API in JDK 6.
* This function uses new Swing Desktop API in JDK 6.
* To use this with scriptpad, open this in scriptpad
* To use this with scriptpad, open this in scriptpad
* and use "Tools->Run Script" menu.
* and use "Tools->Run Script" menu.
*/
*/
function
mail
()
{
function
mail
()
{
with
(
guiPkgs
)
{
var
desktop
=
null
;
var
desktop
=
null
;
// Before more Desktop API is used, first check
// Before more Desktop API is used, first check
// whether the API is supported by this particular
// whether the API is supported by this particular
// virtual machine (VM) on this particular host.
// virtual machine (VM) on this particular host.
if
(
java
.
awt
.
Desktop
.
isDesktopSupported
())
{
if
(
Desktop
.
isDesktopSupported
())
{
desktop
=
java
.
awt
.
Desktop
.
getDesktop
();
desktop
=
Desktop
.
getDesktop
();
}
else
{
}
else
{
alert
(
"
no desktop support
"
);
alert
(
"
no desktop support
"
);
return
;
return
;
}
}
if
(
desktop
.
isSupported
(
Desktop
.
Action
.
MAIL
))
{
if
(
desktop
.
isSupported
(
java
.
awt
.
Desktop
.
Action
.
MAIL
))
{
var
mailTo
=
prompt
(
"
Mail To:
"
);
var
mailTo
=
prompt
(
"
Mail To:
"
);
if
(
mailTo
!=
null
)
{
if
(
mailTo
!=
null
)
{
desktop
.
mail
(
new
java
.
net
.
URI
(
"
mailto
"
,
mailTo
,
null
));
desktop
.
mail
(
new
java
.
net
.
URI
(
"
mailto
"
,
mailTo
,
null
));
}
}
}
}
}
}
}
...
...
src/share/sample/scripting/scriptpad/src/scripts/memmonitor.js
浏览文件 @
f9b20744
/*
/*
* Copyright (c) 2006, 201
1
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 201
3
, 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
...
@@ -37,36 +37,37 @@
...
@@ -37,36 +37,37 @@
* this sample code.
* this sample code.
*/
*/
// this checker function runs asynchronously
// this checker function runs asynchronously
function
memoryChecker
(
memoryBean
,
threshold
,
interval
)
{
function
memoryChecker
(
memoryBean
,
threshold
,
interval
)
{
while
(
true
)
{
while
(
true
)
{
var
memUsage
=
memoryBean
.
HeapMemoryUsage
;
var
memUsage
=
memoryBean
.
HeapMemoryUsage
;
var
usage
=
memUsage
.
get
(
"
used
"
)
/
(
1024
*
1024
);
var
usage
=
memUsage
.
get
(
"
used
"
)
/
(
1024
*
1024
);
println
(
usage
);
println
(
"
usage:
"
+
usage
);
if
(
usage
>
threshold
)
{
if
(
usage
>
threshold
)
{
alert
(
"
Hey! heap usage threshold exceeded!
"
);
alert
(
"
Hey! heap usage threshold exceeded!
"
);
// after first alert just return.
// after first alert just return.
return
;
return
;
}
}
java
.
lang
.
Thread
.
currentThread
().
sleep
(
interval
);
java
.
lang
.
Thread
.
sleep
(
interval
);
}
}
}
}
// add "Tools->Memory Monitor" menu item
// add "Tools->Memory Monitor" menu item
if
(
this
.
application
!=
undefined
)
{
if
(
this
.
application
!=
undefined
)
{
this
.
application
.
addTool
(
"
Memory Monitor
"
,
this
.
application
.
addTool
(
"
Memory Monitor
"
,
function
()
{
function
()
{
// show threshold box with default of 50 MB
// show threshold box with default of 50 MB
var
threshold
=
prompt
(
"
Threshold (mb)
"
,
50
);
var
threshold
=
prompt
(
"
Threshold (mb)
"
,
50
);
// show interval box with default of 1000 millisec.
// show interval box with default of 1000 millisec.
var
interval
=
prompt
(
"
Sample Interval (ms):
"
,
1000
);
var
interval
=
prompt
(
"
Sample Interval (ms):
"
,
1000
);
var
memoryBean
=
mbean
(
"
java.lang:type=Memory
"
);
var
memoryBean
=
mbean
(
"
java.lang:type=Memory
"
);
// ".future" makes the function to be called
// ".future" makes the function to be called
// asynchronously in a separate thread.
// asynchronously in a separate thread.
memoryChecker
.
future
(
memoryBean
,
threshold
,
interval
);
memoryChecker
.
future
(
memoryBean
,
threshold
,
interval
);
});
});
}
}
src/share/sample/scripting/scriptpad/src/scripts/memory.js
浏览文件 @
f9b20744
/*
/*
* Copyright (c) 2006, 201
1
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 201
3
, 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
...
@@ -37,7 +37,6 @@
...
@@ -37,7 +37,6 @@
* this sample code.
* this sample code.
*/
*/
/*
/*
* This script serves as a simple "monitored application".
* This script serves as a simple "monitored application".
* Start this script using memory.bat or memory.sh in the
* Start this script using memory.bat or memory.sh in the
...
@@ -45,12 +44,11 @@
...
@@ -45,12 +44,11 @@
*/
*/
java
.
lang
.
System
.
out
.
print
(
"
Enter a number and press enter:
"
);
java
.
lang
.
System
.
out
.
print
(
"
Enter a number and press enter:
"
);
java
.
lang
.
System
[
"
in
"
].
read
();
var
input
=
java
.
lang
.
System
[
"
in
"
].
read
();
// allocate an integer array of "big enough" size!
// allocate an integer array of "big enough" size!
var
a
=
java
.
lang
.
reflect
.
Array
.
newInstance
(
var
a
=
java
.
lang
.
reflect
.
Array
.
newInstance
(
java
.
lang
.
Integer
.
TYPE
,
1024
*
1024
);
java
.
lang
.
Integer
.
TYPE
,
input
*
1024
*
1024
);
// loop forever!
while
(
true
);
// sleep some time...
java
.
lang
.
Thread
.
sleep
(
10
*
60
*
1000
);
src/share/sample/scripting/scriptpad/src/scripts/memory.sh
浏览文件 @
f9b20744
...
@@ -30,7 +30,3 @@
...
@@ -30,7 +30,3 @@
#
#
jrunscript
-J-Dcom
.sun.management.jmxremote.port
=
1090
-J-Dcom
.sun.management.jmxremote.ssl
=
false
-J-Dcom
.sun.management.jmxremote.authenticate
=
false
memory.js
jrunscript
-J-Dcom
.sun.management.jmxremote.port
=
1090
-J-Dcom
.sun.management.jmxremote.ssl
=
false
-J-Dcom
.sun.management.jmxremote.authenticate
=
false
memory.js
src/share/sample/scripting/scriptpad/src/scripts/textcolor.js
浏览文件 @
f9b20744
/*
/*
* Copyright (c) 2006, 201
1
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 201
3
, 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
...
@@ -37,14 +37,13 @@
...
@@ -37,14 +37,13 @@
* this sample code.
* this sample code.
*/
*/
/*
/*
* This script adds "Selected Text Color" menu item to "Tools" menu.
* This script adds "Selected Text Color" menu item to "Tools" menu.
* When selected, this menu changes the "selected text" color.
* When selected, this menu changes the "selected text" color.
*/
*/
if
(
this
.
application
)
{
if
(
this
.
application
)
{
application
.
addTool
(
"
Selected Text Color...
"
,
application
.
addTool
(
"
Selected Text Color...
"
,
function
()
{
function
()
{
var
color
=
application
.
editor
.
selectedTextColor
;
var
color
=
application
.
editor
.
selectedTextColor
;
color
=
colorDialog
(
"
Selected Text Color
"
,
color
);
color
=
colorDialog
(
"
Selected Text Color
"
,
color
);
application
.
editor
.
selectedTextColor
=
color
;
application
.
editor
.
selectedTextColor
=
color
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录