Java 类javafx.scene.input.InputMethodTextRun 实例源码

项目:JXTN    文件:FXCanvas2.java   
private void sendInputMethodEventToFX()
{
    String text = this.getTextForEvent(this.ime.getText());
    EmbeddedSceneInterface scenePeer = this.getScenePeer();
    if (scenePeer != null)
    {
        String committed = text.substring(0, this.ime.getCommitCount());
        if (this.ime.getText().length() == this.ime.getCommitCount())
        {
            // Send empty text when committed, because the actual chars will then be immediately sent via keys.
            scenePeer.inputMethodEvent(
                    javafx.scene.input.InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
                    FXCollections.emptyObservableList(), "", this.ime.getCompositionOffset());
        }
        else
        {
            ObservableList<InputMethodTextRun> composed = this.inputMethodEventComposed(text, this.ime.getCommitCount());
            scenePeer.inputMethodEvent(
                    javafx.scene.input.InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
                    composed, committed, this.ime.getCaretOffset());
            this.updateImeCandicatePos();
        }
    }
}
项目:JXTN    文件:FXCanvas2.java   
private ObservableList<InputMethodTextRun> inputMethodEventComposed(String text, int commitCount)
{
    List<InputMethodTextRun> composed = new ArrayList<>();
    if (commitCount < text.length())
    {
        composed.add(new InputMethodTextRun(
                text.substring(commitCount), InputMethodHighlight.UNSELECTED_RAW));
    }
    return new ObservableListWrapper<>(composed);
}
项目:openjfx-8u-dev-tests    文件:SceneInputApp.java   
@Override
public void start(Stage stage) {
    VBox vb = new VBox();
    Scene scene = new Scene(vb);
    stage.setScene(scene);
    stage.setWidth(500);
    stage.setHeight(480);

    Pane p = new Pane();
    p.setTranslateX(75);
    p.setTranslateY(75);
    final Text strOutput = new Text();
    strOutput.setId("strOutput");


    MyTextInput mti = new MyTextInput();
    mti.setId("inputfield");
    TextInputControl www = new TextField("bwbeb");
    for (ConditionalFeature c : ConditionalFeature.values()) {
        System.out.println(c);
    }


    EventHandler<? super InputEvent> qqq = new EventHandler<InputEvent>() {

        public void handle(InputEvent e) {
            System.out.println("*");
            //strOutput.setText("ok"); // let it be here for debug
        }
    };

    EventHandler<? super InputMethodEvent> qqq2 = new EventHandler<InputMethodEvent>() {

        public void handle(InputMethodEvent t) {
            strOutput.setText("ok");

            // TODO: test all these getters listed below.
            // "setOnInputMethodTextChanged" does not work now (see http://javafx-jira.kenai.com/browse/RT-12915),
            // and exact values returned by getters are not documented in details, so,
            // this test should be improved and expanded after RT-12915 fix.

            int caretPosition = t.getCaretPosition();
            String committedString = t.getCommitted();
            String strRepresentation = t.toString();
            ObservableList<InputMethodTextRun> lstRun =t.getComposed();
            for (InputMethodTextRun run: lstRun) {
                String runText = run.getText();
                String runString = run.toString();
                InputMethodHighlight imh = run.getHighlight();
                InputMethodHighlight imh1 = InputMethodHighlight.SELECTED_RAW;
                InputMethodHighlight imh2 = InputMethodHighlight.valueOf("SELECTED_RAW");
            }
        }
    };

    mti.setOnInputMethodTextChanged(qqq2);
    mti.setOnKeyTyped(qqq);
    www.setOnInputMethodTextChanged(qqq2);
    www.setOnKeyTyped(qqq);

    vb.getChildren().add(mti);
    vb.getChildren().add(www);
    vb.getChildren().add(strOutput);

    stage.show();
}