예제 #1
0
  public void setString(String newval) {
    JSObject firstChild = null; // used in SPAN

    try {
      if (nodeName == OBJECT_NAME || nodeName == APPLET_NAME) {
        Object[] args = {newval};
        jsObject.call("setString", args);
        return;
      }

      if (nodeName == SPAN_NAME) {
        Object[] args = {newval};
        firstChild = (JSObject) jsObject.getMember("firstChild");
        if (firstChild == null) {
          // FIX create the text child node
          System.err.println("FIX: no child for " + jsObject);
        }
        firstChild.setMember("nodeValue", newval);
        return;
      }

      if (nodeName == INPUT_NAME) {
        String inputType = jsObject.getMember("type").toString().intern();
        if (inputType.equals(RADIO_INPUT)) {
          JSObject radioGroup = groupOfRadioInput(jsObject);
          int groupLength = ((Double) radioGroup.getMember("length")).intValue();
          for (int i = 0; i < groupLength; i += 1) {
            JSObject radioInGroup = (JSObject) radioGroup.getSlot(i);
            String radiosVal = (String) radioInGroup.getMember("value");
            if (radiosVal.equals(newval)) radioInGroup.setMember("checked", Boolean.TRUE);
            else radioInGroup.removeMember("checked");
          }
          return;
        } else {
          // default INPUT control
          jsObject.setMember("value", newval);
          return;
        }
      }

      if (nodeName == TEXTAREA_NAME) {
        jsObject.setMember("value", newval);
        return;
      }

    } catch (Exception ex) {
      System.err.println("setString error on " + jsObject);
      ex.printStackTrace();
      return;
    }

    // no matches
    throw new IllegalStateException("setString does not support nodeName " + nodeName);
  }
 public void setClient(WebView view) {
   this.view = view;
   this.engine = view.getEngine();
   JSObject window = (JSObject) engine.executeScript("window");
   window.setMember("ide", this);
   Collection<IEclipseToBrowserFunction> onLoadFunctions =
       new ArrayList<IEclipseToBrowserFunction>();
   IConfigurationElement[] extensions =
       BrowserExtensions.getExtensions(
           BrowserExtensions.EXTENSION_ID_ECLIPSE_TO_BROWSER,
           null,
           view.getEngine().locationProperty().get());
   for (IConfigurationElement element : extensions) {
     try {
       String onLoad = element.getAttribute(BrowserExtensions.ELEMENT_ONLOAD);
       if (onLoad != null && onLoad.equals("true")) {
         onLoadFunctions.add(
             (IEclipseToBrowserFunction)
                 WorkbenchPlugin.createExtension(element, BrowserExtensions.ELEMENT_CLASS));
       }
     } catch (CoreException ex) {
       StatusManager.getManager()
           .handle(
               new Status(
                   IStatus.ERROR,
                   IdeUiPlugin.PLUGIN_ID,
                   "Could not instantiate browser element provider extension.",
                   ex));
       return;
     }
   }
   callOnBrowser(onLoadFunctions);
 }
예제 #3
0
 /** Register instances of the bridge classes as javascript objects */
 private void addJSBridges() {
   // create the Java object in a scope where they won't be collected by the GC
   JSBridge jsobjBridge = new JSBridge();
   FeedbackUtil jsobjFeedbackUtil = new FeedbackUtil();
   webEngine
       .getLoadWorker()
       .stateProperty()
       .addListener(
           (ov, oldState, newState) -> {
             if (newState == State.SUCCEEDED) {
               JSObject jsobj = (JSObject) webEngine.executeScript("window");
               jsobj.setMember("java", jsobjBridge);
               jsobj.setMember("feedbackUtil", jsobjFeedbackUtil);
               webEngine.executeScript("javaReady();");
             }
           });
 }
예제 #4
0
  public void workerStateChanged(
      ObservableValue<? extends Worker.State> observable,
      Worker.State oldValue,
      Worker.State newValue) {
    if (newValue == Worker.State.READY || newValue == Worker.State.SCHEDULED) {
      if (trafficBrowser != null) {
        trafficBrowser.setStartTime(Instant.now());
        trafficBrowser.getTraffic().clear();
      }
      numberOfAlerts.setValue("0");
    } else if (newValue == Worker.State.SUCCEEDED) {
      JSObject result = (JSObject) webEngine.executeScript("window");

      result.setMember(
          "burpCallbacks",
          new BurpExtenderCallbacksBridge(webEngine, BurpExtender.getBurpExtenderCallbacks()));

      result.setMember("burpKit", javaScriptHelpers);

      //            result.setMember("locals", locals);
      //
      //            result.setMember("globals", globals);

      if (controller != null) {
        result.setMember("burpController", controller);
      }
    } else if (newValue == Worker.State.FAILED) {
      dialog
          .title("Navigation Failed")
          .message(webEngine.getLoadWorker().getException().getMessage())
          .showInformation();
      resetParents();
    } else if (newValue == Worker.State.CANCELLED) {
      dialog
          .title("Navigation Cancelled")
          .message(webEngine.getLoadWorker().getMessage())
          .showInformation();
      resetParents();
    }
  }
예제 #5
0
  /**
   * Creates event listener. <br>
   * This uses the 'upcall' feature from java-script to java.
   *
   * @param editor
   */
  private void setEventCatchers(JSObject editor) {
    // set interface object
    editor.setMember("mAceEvent", new AceEvents(this));

    // on editor events
    editor.eval("this.on('blur', function() { editor.mAceEvent.onBlur(); });");
    editor.eval("this.on('change', function(e) { editor.mAceEvent.onChange(e); });");
    editor.eval(
        "this.on('changeSelectionStyle', function(e) { editor.mAceEvent.onChangeSelectionStyle(e); });");
    editor.eval("this.on('changeSession', function(e) { editor.mAceEvent.onChangeSession(e); });");
    editor.eval("this.on('copy', function(e) { editor.mAceEvent.onCopy(e); });");
    editor.eval("this.on('focus', function() { editor.mAceEvent.onFocus(); });");
    editor.eval("this.on('paste', function(e) { editor.mAceEvent.onPaste(e); });");

    // on edit session events
    editor.eval(
        "this.getSession().on('changeAnnotation', function() { editor.mAceEvent.onChangAnnotation(); });");
    editor.eval(
        "this.getSession().on('changeBackMarker', function() { editor.mAceEvent.onChangeBackMarker(); });");
    editor.eval(
        "this.getSession().on('changeBreakpoint', function() { editor.mAceEvent.onChangeBreakpoint(); });");
    editor.eval(
        "this.getSession().on('changeFold', function() { editor.mAceEvent.onChangeFold(); });");
    editor.eval(
        "this.getSession().on('changeFrontMarker', function() { editor.mAceEvent.onChangeFrontMarker(); });");
    editor.eval(
        "this.getSession().on('changeMode', function() { editor.mAceEvent.onChangeMode(); });");
    editor.eval(
        "this.getSession().on('changeOverwrite', function() { editor.mAceEvent.onChangeOverwrite(); });");
    editor.eval(
        "this.getSession().on('changeScrollLeft', function(e) { editor.mAceEvent.onChangeScrollLeft(e); });");
    editor.eval(
        "this.getSession().on('changeScrollTop', function(e) { editor.mAceEvent.onChangeScrollTop(e); });");
    editor.eval(
        "this.getSession().on('changeTabSize', function() { editor.mAceEvent.onChangeTabSize(); });");
    editor.eval(
        "this.getSession().on('changeWrapLimit', function() { editor.mAceEvent.onChangeWrapLimit(); });");
    editor.eval(
        "this.getSession().on('changeWrapMode', function() { editor.mAceEvent.onChangeWrapMode(); });");
    editor.eval(
        "this.getSession().on('tokenizerUpdate', function(e) { editor.mAceEvent.onTokenizerUpadate(e); });");

    addEventHandler(
        AceEvents.onChangeEvent,
        new EventHandler<Event>() {
          @Override
          public void handle(Event event) {
            undoButton.setDisable(!getUndoManager().hasUndo());
            redoButton.setDisable(!getUndoManager().hasRedo());
          }
        });
  }
예제 #6
0
파일: Symbol.java 프로젝트: ex00/javafx-d3
  /**
   * Set the size of the symbols using the specified function returning an integer.
   *
   * <p>
   *
   * @param sizeAccessorFunction the function that return the {@link DragEventType} of symbol.
   * @return this instance for chaining
   */
  public Symbol size(DatumFunction<Integer> sizeAccessorFunction) {

    assertObjectIsNotAnonymous(sizeAccessorFunction);

    JSObject d3JsObject = getD3();
    String accessorName = createNewTemporaryInstanceName();

    d3JsObject.setMember(accessorName, sizeAccessorFunction);

    String command =
        "this.size(function(d, i) {" //
            + "return d3."
            + accessorName
            + ".apply(this,{datum:d},i);" //
            + " });";
    JSObject result = evalForJsObject(command);
    return new Symbol(webEngine, result);
  }
예제 #7
0
파일: Chord.java 프로젝트: ex00/javafx-d3
  /**
   * Set the source accessor.
   *
   * <p>The purpose of the source accessor is to return an object that describes the starting arc of
   * the chord. The returned object is subsequently passed to the {@link #radius(DatumFunction)},
   * {@link #startAngle(DatumFunction)} and {@link #endAngle(DatumFunction)} accessors.
   *
   * <p>This allows these other accessors to be reused for both the source and target arc
   * descriptions.
   *
   * <p>The default accessor assumes that the input data is a JavaScriptObject with suitably-named
   * attributes.
   *
   * <p>The source-accessor is invoked in the same manner as other value functions in D3.
   *
   * <p>
   *
   * @param accessor the function returning the source arc object
   * @return the current chord generator
   */
  public Chord source(final DatumFunction<?> accessor) {

    assertObjectIsNotAnonymous(accessor);

    JSObject d3JsObject = getD3();
    String accessorName = createNewTemporaryInstanceName();
    d3JsObject.setMember(accessorName, accessor);

    String command =
        "this.source(function(d, i) { " //
            + "return d3."
            + accessorName
            + ".apply(this,{datum:d},i);" //
            + " });";

    JSObject result = evalForJsObject(command);
    return new Chord(webEngine, result);
  }
예제 #8
0
  /**
   * Delete a cookie
   *
   * @param name The name of the cookie
   */
  protected void deleteCookie(String name) {
    setCookie(name, " ");
    /*
     **  delete a cookie, set the expiration in the past
     */
    java.util.Calendar c = java.util.Calendar.getInstance();
    c.add(java.util.Calendar.MONTH, -1);
    String expires = "; expires=" + c.getTime().toString();

    String s1 = name + expires;
    try {
      JSObject myBrowser = JSObject.getWindow(applet);
      JSObject myDocument = (JSObject) myBrowser.getMember("document");
      LOG.debug("del: " + s1);
      myDocument.setMember("cookie", s1);
    } catch (JSException e) {
      LOG.error("deleteCookie " + name + " failed", e);
    }
  }
예제 #9
0
  /**
   * Write a cookie
   *
   * @param name The name of the cookie
   * @param value The value to write
   */
  protected void setCookie(String name, String value) {
    value = cleanValue(value);
    /*
     **  write a cookie
     **    computes the expiration date, good for 1 month
     */
    java.util.Calendar c = java.util.Calendar.getInstance();
    c.add(java.util.Calendar.YEAR, 1);
    String expires = "; expires=" + c.getTime().toString();

    String s1 = name + "=" + value + expires;
    LOG.debug(s1);
    try {
      JSObject myBrowser = JSObject.getWindow(applet);
      JSObject myDocument = (JSObject) myBrowser.getMember("document");

      myDocument.setMember("cookie", s1);
      LOG.debug("set:" + s1);
    } catch (JSException e) {
      LOG.error("setCookie " + name + "=" + value + " failed", e);
    }
  }
예제 #10
0
파일: Zoom.java 프로젝트: ex00/javafx-d3
  /**
   * Registers the specified listener to receive events of the specified type from the zoom
   * behavior.
   *
   * <p>See {@link ZoomEventType} for more information.
   *
   * <p>If an event listener was already registered for the same type, the existing listener is
   * removed before the new listener is added. TODO: To register multiple listeners for the same
   * event type, the type may be followed by an optional namespace, such as "zoom.foo" and
   * "zoom.bar". To remove a listener, pass null as the listener.
   *
   * <p>For mousewheel events, which happen discretely with no explicit start and end reported by
   * the browser, events that occur within 50 milliseconds of each other are grouped into a single
   * zoom gesture. If you want more robust interpretation of these gestures, please petition your
   * browser vendor of choice for better touch event support.
   *
   * <p>
   *
   * @param type
   * @param listener
   * @return the current zoom instance
   */
  public Zoom on(ZoomEventType type, DatumFunction<Void> listener) {

    assertObjectIsNotAnonymous(listener);

    String listenerName = createNewTemporaryInstanceName();
    JSObject d3JsObject = getD3();
    d3JsObject.setMember(listenerName, listener);

    String eventName = type.name().toLowerCase();

    String command =
        "this.on('"
            + eventName
            + "', "
            + "function(d, index) { " //
            + "d3."
            + listenerName
            + ".apply(this,{datum:d},index);" //
            + " });";

    JSObject result = evalForJsObject(command);
    return new Zoom(webEngine, result);
  }
예제 #11
0
  public Browser(final Stage stage) {
    // apply the styles
    getStyleClass().add("browser");

    for (int i = 0; i < captions.length; i++) {
      // create hyperlinks
      Hyperlink hpl = hpls[i] = new Hyperlink(captions[i]);
      Image image = images[i] = new Image(getClass().getResourceAsStream(imageFiles[i]));
      hpl.setGraphic(new ImageView(image));
      final String url = urls[i];
      final boolean addButton = (hpl.getText().equals("Help"));

      // process event
      hpl.setOnAction(
          (ActionEvent e) -> {
            needDocumentationButton = addButton;
            webEngine.load(url);
          });
    }

    comboBox.setPrefWidth(60);

    // create the toolbar
    toolBar = new HBox();
    toolBar.setAlignment(Pos.CENTER);
    toolBar.getStyleClass().add("browser-toolbar");
    toolBar.getChildren().add(comboBox);
    toolBar.getChildren().addAll(hpls);
    toolBar.getChildren().add(createSpacer());

    // set action for the button
    toggleHelpTopics.setOnAction(
        (ActionEvent t) -> {
          webEngine.executeScript("toggle_visibility('help_topics')");
        });

    smallView.setPrefSize(120, 80);

    // handle popup windows
    webEngine.setCreatePopupHandler(
        (PopupFeatures config) -> {
          smallView.setFontScale(0.8);
          if (!toolBar.getChildren().contains(smallView)) {
            toolBar.getChildren().add(smallView);
          }
          return smallView.getEngine();
        });

    // process history
    final WebHistory history = webEngine.getHistory();
    history
        .getEntries()
        .addListener(
            (Change<? extends Entry> c) -> {
              c.next();
              c.getRemoved()
                  .stream()
                  .forEach(
                      (e) -> {
                        comboBox.getItems().remove(e.getUrl());
                      });
              c.getAddedSubList()
                  .stream()
                  .forEach(
                      (e) -> {
                        comboBox.getItems().add(e.getUrl());
                      });
            });

    // set the behavior for the history combobox
    comboBox.setOnAction(
        (Event ev) -> {
          int offset = comboBox.getSelectionModel().getSelectedIndex() - history.getCurrentIndex();
          history.go(offset);
        });

    // process page loading
    webEngine
        .getLoadWorker()
        .stateProperty()
        .addListener(
            (ObservableValue<? extends State> ov, State oldState, State newState) -> {
              toolBar.getChildren().remove(toggleHelpTopics);
              if (newState == State.SUCCEEDED) {
                JSObject win = (JSObject) webEngine.executeScript("window");
                win.setMember("app", new JavaApp());
                if (needDocumentationButton) {
                  toolBar.getChildren().add(toggleHelpTopics);
                }
              }
            });
    // adding context menu
    final ContextMenu cm = new ContextMenu();
    MenuItem cmItem1 = new MenuItem("Print");
    cm.getItems().add(cmItem1);
    toolBar.addEventHandler(
        MouseEvent.MOUSE_CLICKED,
        (MouseEvent e) -> {
          if (e.getButton() == MouseButton.SECONDARY) {
            cm.show(toolBar, e.getScreenX(), e.getScreenY());
          }
        });

    // processing print job
    cmItem1.setOnAction(
        (ActionEvent e) -> {
          PrinterJob job = PrinterJob.createPrinterJob();
          if (job != null) {
            webEngine.print(job);
            job.endJob();
          }
        });

    // load the home page
    webEngine.load("http://www.cnn.com");

    // add components
    getChildren().add(toolBar);
    getChildren().add(browser);
  }
예제 #12
0
  public void addTab(Path path, Runnable... runnables) {

    ObservableList<String> recentFiles = controller.getRecentFilesList();
    if (Files.notExists(path)) {
      recentFiles.remove(path.toString());
      return;
    }

    ObservableList<Tab> tabs = controller.getTabPane().getTabs();
    for (Tab tab : tabs) {
      MyTab myTab = (MyTab) tab;
      Path currentPath = myTab.getPath();
      if (Objects.nonNull(currentPath))
        if (currentPath.equals(path)) {
          myTab.select(); // Select already added tab
          return;
        }
    }

    AnchorPane anchorPane = new AnchorPane();
    EditorPane editorPane = webviewService.createWebView();

    MyTab tab = createTab();
    tab.setEditorPane(editorPane);
    tab.setTabText(path.getFileName().toString());

    editorPane.confirmHandler(
        param -> {
          if ("command:ready".equals(param)) {
            JSObject window = editorPane.getWindow();
            window.setMember("afx", controller);
            window.call("updateOptions", new Object[] {});
            Map<String, String> shortCuts = controller.getShortCuts();
            Set<String> keySet = shortCuts.keySet();
            for (String key : keySet) {
              window.call("addNewCommand", new Object[] {key, shortCuts.get(key)});
            }
            if (Objects.isNull(path)) return true;
            threadService.runTaskLater(
                () -> {
                  String content = IOHelper.readFile(path);
                  threadService.runActionLater(
                      () -> {
                        window.call("changeEditorMode", path.toUri().toString());
                        window.call("setInitialized");
                        window.call("setEditorValue", new Object[] {content});
                        for (Runnable runnable : runnables) {
                          runnable.run();
                        }
                      });
                });
          }
          return false;
        });

    threadService.runActionLater(
        () -> {
          TabPane tabPane = controller.getTabPane();
          tabPane.getTabs().add(tab);
          tab.select();
        });

    Node editorVBox = editorService.createEditorVBox(editorPane, tab);
    controller.fitToParent(editorVBox);

    anchorPane.getChildren().add(editorVBox);
    tab.setContent(anchorPane);
    tab.setPath(path);

    Tooltip tip = new Tooltip(path.toString());
    Tooltip.install(tab.getGraphic(), tip);

    recentFiles.remove(path.toString());
    recentFiles.add(0, path.toString());

    editorPane.focus();
  }
 @Override
 public void changed(
     ObservableValue<? extends State> observable, State oldValue, State newValue) {
   JSObject win = (JSObject) getWebViewGuaranteed().getEngine().executeScript("window");
   win.setMember("JavaPanelBridge", new JavaPanelBridge());
 }
예제 #14
0
 public ContentAssistImpl(ContentProposalComputer computer, JSObject jsObject) {
   jsObject.setMember("__javaObject", this);
   this.computer = computer;
 }