javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/Console.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Fri, 12 Apr 2013 15:42:05 +0200
branchfx
changeset 972 fbabd1f33dda
permissions -rw-r--r--
console.log(...) realy logs something
jaroslav@972
     1
/**
jaroslav@972
     2
 * Back 2 Browser Bytecode Translator
jaroslav@972
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@972
     4
 *
jaroslav@972
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@972
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@972
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@972
     8
 *
jaroslav@972
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@972
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@972
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@972
    12
 * GNU General Public License for more details.
jaroslav@972
    13
 *
jaroslav@972
    14
 * You should have received a copy of the GNU General Public License
jaroslav@972
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@972
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@972
    17
 */
jaroslav@972
    18
package org.apidesign.bck2brwsr.htmlpage;
jaroslav@972
    19
jaroslav@972
    20
import java.util.logging.Logger;
jaroslav@972
    21
import javafx.scene.web.WebEngine;
jaroslav@972
    22
import netscape.javascript.JSObject;
jaroslav@972
    23
jaroslav@972
    24
/**
jaroslav@972
    25
 *
jaroslav@972
    26
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@972
    27
 */
jaroslav@972
    28
public class Console {
jaroslav@972
    29
    private static final Logger LOG = Logger.getLogger(Console.class.getName());
jaroslav@972
    30
    
jaroslav@972
    31
    private Console() {
jaroslav@972
    32
    }
jaroslav@972
    33
jaroslav@972
    34
    static void register(WebEngine web) {
jaroslav@972
    35
        ((JSObject)web.executeScript("window")).setMember("jconsole", new Console());
jaroslav@972
    36
        web.executeScript("console.log = function(m) { jconsole.log(m); };");
jaroslav@972
    37
        web.executeScript("console.info = function(m) { jconsole.log(m); };");
jaroslav@972
    38
        web.executeScript("console.error = function(m) { jconsole.log(m); };");
jaroslav@972
    39
        web.executeScript("console.warn = function(m) { jconsole.log(m); };");
jaroslav@972
    40
    }
jaroslav@972
    41
    
jaroslav@972
    42
    public void log(String msg) {
jaroslav@972
    43
        LOG.info(msg);
jaroslav@972
    44
    }
jaroslav@972
    45
}