⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jconsole.js

📁 一个小公司要求给写的很简单的任务管理系统。
💻 JS
📖 第 1 页 / 共 2 页
字号:
    var func = this;    return new java.lang.Runnable() {        run: function() {            func.apply(null, args);        }    }}/** * Executes the function on a new Java Thread. */Function.prototype.thread = function() {    var t = new java.lang.Thread(this.runnable.apply(this, arguments));    t.start();    return t;}/** * Executes the function on a new Java daemon Thread. */Function.prototype.daemon = function() {    var t = new java.lang.Thread(this.runnable.apply(this, arguments));    t.setDaemon(true);    t.start();    return t;}/** * Creates a java.util.concurrent.Callable from a given script * function. */Function.prototype.callable = function() {    var args = arguments;    var func = this;    return new java.util.concurrent.Callable() {          call: function() { return func.apply(null, args); }    }}/** * Registers the script function so that it will be called exit. */Function.prototype.atexit = function () {    var args = arguments;    java.lang.Runtime.getRuntime().addShutdownHook(         new java.lang.Thread(this.runnable.apply(this, args)));}/** * Executes the function asynchronously.   * * @return a java.util.concurrent.FutureTask */Function.prototype.future = (function() {    // default executor for future    var juc = java.util.concurrent;    var theExecutor = juc.Executors.newSingleThreadExecutor();    // clean-up the default executor at exit    (function() { theExecutor.shutdown(); }).atexit();    return function() {        return theExecutor.submit(this.callable.apply(this, arguments));    }})();// shortcut for j.u.c lock classesvar Lock = java.util.concurrent.locks.ReentrantLock;var RWLock = java.util.concurrent.locks.ReentrantReadWriteLock;/** * Executes a function after acquiring given lock. On return, * (normal or exceptional), lock is released. * * @param lock lock that is locked and unlocked */Function.prototype.sync = function (lock) {    if (arguments.length == 0) {        throw "lock is missing";    }    var res = new Array(arguments.length - 1);    for (var i = 0; i < res.length; i++) {        res[i] = arguments[i + 1];    }    lock.lock();    try {        this.apply(null, res);    } finally {        lock.unlock();    }}/** * Causes current thread to sleep for specified * number of milliseconds * * @param interval in milliseconds */function sleep(interval) {    java.lang.Thread.sleep(interval);}sleep.docString = "wrapper for java.lang.Thread.sleep method";/** * 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 setTimeout(callback, interval) {    if (! (callback instanceof Function)) {        callback = new Function(callback);    }    // start a new thread that sleeps given time    // and calls callback in an infinite loop    return (function() {         while (true) {             sleep(interval);             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();}/** * Simple access to thread local storage.  * * Script sample: * *  __thread.x = 44; *  function f() {  *      __thread.x = 'hello';  *      print(__thread.x);  *  } *  f.thread();       // prints 'hello' * print(__thread.x); // prints 44 in main thread */var __thread = (function () {    var map = new Object();    return new JSAdapter() {        __has__: function(name) {            return map[name] != undefined;        },        __get__: function(name) {            if (map[name] != undefined) {                return map[name].get();            } else {                return undefined;            }        },        __put__: sync(function(name, value) {            if (map[name] == undefined) {                var tmp = new java.lang.ThreadLocal();                tmp.set(value);                map[name] = tmp;            } else {                map[name].set(value);            }        }),        __delete__: function(name) {            if (map[name] != undefined) {                map[name].set(null);            }                    }    }})();// user interface utilities/**  * Swing invokeLater - invokes given function in AWT event thread */Function.prototype.invokeLater = function() {    var SwingUtilities = Packages.javax.swing.SwingUtilities;    SwingUtilities.invokeLater(this.runnable.apply(this, arguments));}/**  * Swing invokeAndWait - invokes given function in AWT event thread * and waits for it's completion */Function.prototype.invokeAndWait = function() {    var SwingUtilities = Packages.javax.swing.SwingUtilities;    SwingUtilities.invokeAndWait(this.runnable.apply(this, arguments));}/** * Am I running in AWT event dispatcher thread? */function isEventThread() {    var SwingUtilities = Packages.javax.swing.SwingUtilities;    return SwingUtilities.isEventDispatchThread();}isEventThread.docString = "returns whether the current thread is GUI thread";/** * Opens a file dialog box  * * @param curDir current directory [optional] * @return absolute path if file selected or else null */function fileDialog(curDir) {    var result;    function _fileDialog() {        if (curDir == undefined) curDir = undefined;        var JFileChooser = Packages.javax.swing.JFileChooser;        var dialog = new JFileChooser(curDir);        var res = dialog.showOpenDialog(null);        if (res == JFileChooser.APPROVE_OPTION) {            result = dialog.getSelectedFile().getAbsolutePath();        } else {           result = null;        }    }    if (isEventThread()) {        _fileDialog();    } else {        _fileDialog.invokeAndWait();    }    return result;}fileDialog.docString = "show a FileOpen dialog box";/** * Shows a message box * * @param msg message to be shown * @param title title of message box [optional] * @param msgType type of message box [constants in JOptionPane] */function msgBox(msg, title, msgType) {       function _msgBox() {         var JOptionPane = Packages.javax.swing.JOptionPane;        if (msg === undefined) msg = "undefined";        if (msg === null) msg = "null";        if (title == undefined) title = msg;        if (msgType == undefined) type = JOptionPane.INFORMATION_MESSAGE;        JOptionPane.showMessageDialog(window, msg, title, msgType);    }    if (isEventThread()) {        _msgBox();    } else {        _msgBox.invokeAndWait();    }}msgBox.docString = "shows MessageBox to the user"; /** * Shows an information alert box * * @param msg message to be shown * @param title title of message box [optional] */   function alert(msg, title) {    var JOptionPane = Packages.javax.swing.JOptionPane;    msgBox(msg, title, JOptionPane.INFORMATION_MESSAGE);}alert.docString = "shows an alert message box to the user";/** * Shows an error alert box * * @param msg message to be shown * @param title title of message box [optional] */function error(msg, title) {    var JOptionPane = Packages.javax.swing.JOptionPane;    msgBox(msg, title, JOptionPane.ERROR_MESSAGE);}error.docString = "shows an error message box to the user";/** * Shows a warning alert box * * @param msg message to be shown * @param title title of message box [optional] */function warn(msg, title) {    var JOptionPane = Packages.javax.swing.JOptionPane;    msgBox(msg, title, JOptionPane.WARNING_MESSAGE);}warn.docString = "shows a warning message box to the user";/** * Shows a prompt dialog box * * @param question question to be asked * @param answer default answer suggested [optional] * @return answer given by user */function prompt(question, answer) {    var result;    function _prompt() {        var JOptionPane = Packages.javax.swing.JOptionPane;        if (answer == undefined) answer = "";        result = JOptionPane.showInputDialog(window, question, answer);    }    if (isEventThread()) {        _prompt();    } else {        _prompt.invokeAndWait();    }    return result;}prompt.docString = "shows a prompt box to the user and returns the answer";/** * Shows a confirmation dialog box * * @param msg message to be shown * @param title title of message box [optional] * @return boolean (yes->true, no->false) */function confirm(msg, title) {    var result;    var JOptionPane = Packages.javax.swing.JOptionPane;    function _confirm() {        if (title == undefined) title = msg;        var optionType = JOptionPane.YES_NO_OPTION;        result = JOptionPane.showConfirmDialog(null, msg, title, optionType);    }    if (isEventThread()) {        _confirm();    } else {        _confirm.invokeAndWait();    }         return result == JOptionPane.YES_OPTION;}confirm.docString = "shows a confirmation message box to the user";/** * Echoes zero or more arguments supplied to screen. * This is print equivalent for GUI. * * @param zero or more items to echo. */function echo() {    var args = arguments;    (function() {        var len = args.length;        for (var i = 0; i < len; i++) {            window.print(args[i]);            window.print(" ");        }        window.print("\n");    }).invokeLater();}echo.docString = "echoes arguments to interactive console screen";/** * Clear the screen */function clear() {    (function() { window.clear(false) }).invokeLater();}clear.docString = "clears interactive console screen";// synonym for clearvar cls = clear;/** * Exit the process after confirmation from user  *  * @param exitCode return code to OS [optional] */function exit(exitCode) {    if (exitCode == undefined) exitCode = 0;    if (confirm("Do you really want to exit?")) {        java.lang.System.exit(exitCode);    } }exit.docString = "exits jconsole";// synonym to exitvar quit = exit;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -