Search in sources :

Example 11 with IndexRange

use of javafx.scene.control.IndexRange in project RichTextFX by FXMisc.

the class GenericStyledAreaBehavior method handleFirstPrimaryPress.

private void handleFirstPrimaryPress(MouseEvent e) {
    // ensure focus
    view.requestFocus();
    CharacterHit hit = view.hit(e.getX(), e.getY());
    view.clearTargetCaretOffset();
    IndexRange selection = view.getSelection();
    if (view.isEditable() && selection.getLength() != 0 && hit.getCharacterIndex().isPresent() && hit.getCharacterIndex().getAsInt() >= selection.getStart() && hit.getCharacterIndex().getAsInt() < selection.getEnd()) {
        // press inside selection
        dragSelection = DragState.POTENTIAL_DRAG;
        dragNewSelection = DragState.NO_DRAG;
    } else {
        dragSelection = DragState.NO_DRAG;
        dragNewSelection = DragState.NO_DRAG;
        view.getOnOutsideSelectionMousePressed().handle(e);
    }
}
Also used : IndexRange(javafx.scene.control.IndexRange)

Example 12 with IndexRange

use of javafx.scene.control.IndexRange in project RichTextFX by FXMisc.

the class SimpleEditableStyledDocumentTest method testGetStyleRangeAtPosition.

@Test
public void testGetStyleRangeAtPosition() {
    SimpleEditableStyledDocument<String, String> document = new SimpleEditableStyledDocument<>("", "");
    String first = "some";
    String second = " text";
    replaceText(document, 0, 0, first + second);
    document.setStyle(0, first.length(), "abc");
    IndexRange range = document.getStyleRangeAtPosition(0);
    IndexRange expected = new IndexRange(0, first.length());
    assertEquals(expected, range);
    range = document.getStyleRangeAtPosition(first.length());
    assertEquals(expected, range);
    range = document.getStyleRangeAtPosition(first.length() + 1);
    expected = new IndexRange(first.length(), (first + second).length());
    assertEquals(expected, range);
}
Also used : IndexRange(javafx.scene.control.IndexRange) Test(org.junit.Test)

Example 13 with IndexRange

use of javafx.scene.control.IndexRange in project JFoenix by jfoenixadmin.

the class JFXPasswordField method cut.

/**
 *************************************************************************
 *                                                                         *
 * Methods                                                                 *
 *                                                                         *
 *************************************************************************
 */
@Override
public void cut() {
    if (isMaskedText()) {
        // No-op
        return;
    }
    copy();
    IndexRange selection = getSelection();
    deleteText(selection.getStart(), selection.getEnd());
}
Also used : IndexRange(javafx.scene.control.IndexRange)

Example 14 with IndexRange

use of javafx.scene.control.IndexRange in project Gargoyle by callakrsos.

the class ASTSqlCodeAreaHelper method createResourceView.

@Override
public ResourceView<Map<String, Object>> createResourceView() {
    TableOpenResourceView tableOpenResourceView = new TableOpenResourceView(connectionSupplier) {

        /* (non-Javadoc)
			 * @see com.kyj.fx.voeditor.visual.component.popup.TableOpenResourceView#close()
			 */
        @Override
        public void close() {
            super.close();
            codeArea.getPopupWindow().hide();
            ResultDialog<Map<String, Object>> result = getResult();
            if (result.getStatus() == ResultDialog.SELECT) {
                Map<String, Object> data = result.getData();
                if (data == null)
                    return;
                String tableName = getTableName(data);
                if (tableName == null)
                    return;
                //					Object object = data.get("table_name");
                //					if (object == null)
                //						return;
                String string = currentPragraph(codeArea);
                int markTextColumnIndex = getIndexOfValideWhiteSpace(string);
                if (markTextColumnIndex == -1) {
                    codeArea.getUndoManager().mark();
                    codeArea.appendText(tableName);
                } else {
                    int anchor = codeArea.getAnchor();
                    int start = anchor - string.length() + markTextColumnIndex;
                    IndexRange normalize = IndexRange.normalize(start, anchor);
                    codeArea.getUndoManager().mark();
                    codeArea.replaceText(normalize, tableName);
                }
            }
        }
    };
    return tableOpenResourceView.getView();
}
Also used : IndexRange(javafx.scene.control.IndexRange) TableOpenResourceView(com.kyj.fx.voeditor.visual.component.popup.TableOpenResourceView) Map(java.util.Map)

Example 15 with IndexRange

use of javafx.scene.control.IndexRange in project Gargoyle by callakrsos.

the class CodeAreaFindAndReplaceHelper method findReplaceEvent.

/**
	 * 찾기 바꾸기 이벤트
	 *
	 * @작성자 : KYJ
	 * @작성일 : 2016. 10. 13.
	 * @param e
	 */
protected void findReplaceEvent(Event e) {
    if (e.isConsumed())
        return;
    ObservableValue<String> textProperty = codeArea.textProperty();
    TextSearchAndReplaceView textSearchView = new TextSearchAndReplaceView(codeArea, textProperty);
    textSearchView.setOnSearchResultListener((vo) -> {
        switch(vo.getSearchType()) {
            case SEARCH_SIMPLE:
                {
                    int startIndex = vo.getStartIndex();
                    int endIndex = vo.getEndIndex();
                    codeArea.selectRange(startIndex, endIndex);
                    LOGGER.debug(String.format("find text : %s startIdx :%d endIdx :%d", vo.getSearchText(), startIndex, endIndex));
                    break;
                }
            case SEARCH_ALL:
                {
                    int startIndex = vo.getStartIndex();
                    String searchText = vo.getSearchText();
                    String replaceText = vo.getReplaceText();
                    // codeArea.getUndoManager().mark();
                    // codeArea.replaceText(startIndex, (startIndex +
                    // searchText.length()), replaceText);
                    setContent(startIndex, startIndex + searchText.length(), replaceText);
                    break;
                }
        }
    });
    textSearchView.setOnReplaceResultListener(vo -> {
        switch(vo.getReaplceType()) {
            case SIMPLE:
                {
                    String reaplceResult = vo.getReaplceResult();
                    setContent(reaplceResult);
                    break;
                }
            case ALL:
                {
                    String reaplceResult = vo.getReaplceResult();
                    setContent(reaplceResult);
                    break;
                }
        }
    });
    textSearchView.setOnSelectionMoveListener(vo -> {
        codeArea.selectRange(vo.getStartIndex(), vo.getEndIndex());
    });
    textSearchView.isSelectScopePropertyProperty().addListener((oba, oldval, newval) -> {
        if (newval)
            LOGGER.debug("User Select Locale Scope..");
        else
            LOGGER.debug("User Select Gloval Scope..");
    });
    codeArea.setOnMouseClicked(event -> {
        IndexRange selection = codeArea.getSelection();
        int start = selection.getStart();
        textSearchView.setSlidingStartIndexProperty(start);
    });
    textSearchView.show();
    //		codeArea.setOnMouseClicked(defaultSelectionHandler);
    e.consume();
}
Also used : IndexRange(javafx.scene.control.IndexRange) TextSearchAndReplaceView(com.kyj.fx.voeditor.visual.component.popup.TextSearchAndReplaceView)

Aggregations

IndexRange (javafx.scene.control.IndexRange)20 TextSearchAndReplaceView (com.kyj.fx.voeditor.visual.component.popup.TextSearchAndReplaceView)2 DataOutputStream (java.io.DataOutputStream)2 IOException (java.io.IOException)2 List (java.util.List)2 Optional (java.util.Optional)2 BiConsumer (java.util.function.BiConsumer)2 Function (java.util.function.Function)2 FXCollections (javafx.collections.FXCollections)2 Node (javafx.scene.Node)2 Paint (javafx.scene.paint.Paint)2 ReadOnlyStyledDocument (org.fxmisc.richtext.model.ReadOnlyStyledDocument)2 StyledDocument (org.fxmisc.richtext.model.StyledDocument)2 TableOpenResourceView (com.kyj.fx.voeditor.visual.component.popup.TableOpenResourceView)1 TextSearchComposite (com.kyj.fx.voeditor.visual.component.popup.TextSearchComposite)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataInputStream (java.io.DataInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1