Package chrriis.dj.nativeswing.swtimpl.components

Examples of chrriis.dj.nativeswing.swtimpl.components.WebBrowserFunction


  public void registerFunction(WebBrowserFunction function) {
    String functionName = function.getName();
    if(nameToFunctionMap == null) {
      nameToFunctionMap = new HashMap<String, WebBrowserFunction>();
    } else {
      WebBrowserFunction oldFunction = nameToFunctionMap.get(functionName);
      if(oldFunction == function) {
        return;
      }
      if(oldFunction != null) {
        unregisterFunction(oldFunction);
View Full Code Here


  public void unregisterFunction(WebBrowserFunction function) {
    if(nameToFunctionMap == null) {
      return;
    }
    String functionName = function.getName();
    WebBrowserFunction currentFunction = nameToFunctionMap.get(functionName);
    if(currentFunction != function) {
      return;
    }
    nameToFunctionMap.remove(function);
    if(nameToFunctionMap.isEmpty()) {
View Full Code Here

      JWebBrowser webBrowser = nativeWebBrowser == null? null: nativeWebBrowser.webBrowser.get();
      if(webBrowser == null) {
        return null;
      }
      if(nativeWebBrowser.nameToFunctionMap != null) {
        WebBrowserFunction function = nativeWebBrowser.nameToFunctionMap.get(args[0]);
        if(function != null) {
          return function.invoke(webBrowser, (Object[])args[1]);
        }
      }
      return null;
    }
View Full Code Here

    JPanel webBrowserPanel = new JPanel(new BorderLayout());
    webBrowserPanel.setBorder(BorderFactory.createTitledBorder("Native Web Browser component"));
    JWebBrowser webBrowser = new JWebBrowser();
    webBrowser.setBarsVisible(false);
    final JTextArea functionCallsTextArea = new JTextArea(7, 0);
    webBrowser.registerFunction(new WebBrowserFunction("invokeJavaNoError") {
      @Override
      public Object invoke(JWebBrowser webBrowser, Object... args) {
        StringBuilder sb = new StringBuilder();
        sb.append("-> " + getName() + "() called from Javascript with args:");
        for (int i=0; i<args.length; i++) {
          Object arg = args[i];
          if (arg == null) {
            sb.append(LS).append("  null");
          } else {
            sb.append(LS).append("  ").append(arg instanceof Object[]? Arrays.deepToString((Object[])arg): arg.toString()).append(" (").append(arg.getClass().getSimpleName()).append(")");
          }
        }
        sb.append(LS).append("-> return Object[] result:").append(LS).append("  (short)3").append(LS).append("  true").append(LS).append("  null").append(LS).append("  new Object[] {\"A String\", false}").append(LS).append("  \"Hello World!\"").append(LS).append("  2.0f / 3.0f");
        functionCallsTextArea.setText(sb.toString());
        functionCallsTextArea.setCaretPosition(0);
        return new Object[] {(short)3, true, null, new Object[] {"A String", false}, "Hello World!", 2.0f / 3.0f};
      }
    });
    webBrowser.registerFunction(new WebBrowserFunction("invokeJavaWithError") {
      @Override
      public Object invoke(JWebBrowser webBrowser, Object... args) {
        functionCallsTextArea.setText("-> " + getName() + "() called from Javascript." + LS + "-> Generating a Java runtime exception.");
        functionCallsTextArea.setCaretPosition(0);
        // This will generate an error
View Full Code Here

TOP

Related Classes of chrriis.dj.nativeswing.swtimpl.components.WebBrowserFunction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.