Search in sources :

Example 1 with CodeArea

use of org.fxmisc.richtext.CodeArea in project aic-praise by aic-sri-international.

the class HOGMCodeArea method initialize.

//
// PRIVATE
//
private void initialize(boolean showLineNumbers) {
    codeArea = new CodeArea();
    if (showLineNumbers) {
        codeArea.setParagraphGraphicFactory(LineNumberFactory.get(codeArea, digits -> "%" + (digits < 2 ? 2 : digits) + "d"));
    }
    codeArea.textProperty().addListener((obs, oldText, newText) -> {
        codeArea.setStyleSpans(0, computeHighlighting(newText));
    });
    FXUtil.anchor(codeArea);
    getChildren().add(codeArea);
}
Also used : ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream) Collection(java.util.Collection) Token(org.antlr.v4.runtime.Token) CodeArea(org.fxmisc.richtext.CodeArea) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) LineNumberFactory(org.fxmisc.richtext.LineNumberFactory) Beta(com.google.common.annotations.Beta) HOGMTerminalSymbols(com.sri.ai.praise.model.v1.hogm.antlr.HOGMTerminalSymbols) AnchorPane(javafx.scene.layout.AnchorPane) HOGMLexer(com.sri.ai.praise.model.v1.hogm.antlr.HOGMLexer) StyleSpans(org.fxmisc.richtext.StyleSpans) StyleSpansBuilder(org.fxmisc.richtext.StyleSpansBuilder) UndoManager(org.fxmisc.undo.UndoManager) Collections(java.util.Collections) FXUtil(com.sri.ai.praise.sgsolver.demo.FXUtil) CodeArea(org.fxmisc.richtext.CodeArea)

Example 2 with CodeArea

use of org.fxmisc.richtext.CodeArea in project Gargoyle by callakrsos.

the class PagedCodeAreaFindAndReplaceHelper method setContent.

public void setContent(String content) {
    SimpleTextView currentPageView = this.view.getCurrentPageView();
    if (currentPageView != null) {
        CodeArea codeArea = currentPageView.getCodeArea();
        codeArea.getUndoManager().mark();
        codeArea.clear();
        codeArea.replaceText(0, 0, content);
        codeArea.getUndoManager().mark();
    }
}
Also used : CodeArea(org.fxmisc.richtext.CodeArea)

Example 3 with CodeArea

use of org.fxmisc.richtext.CodeArea in project Gargoyle by callakrsos.

the class TextPopupExam method start.

/* (non-Javadoc)
	 * @see javafx.application.Application#start(javafx.stage.Stage)
	 */
//	@Override
//	public void start(Stage primaryStage) throws Exception {
//		CustomTextArea textArea = new CustomTextArea("Hello world.,!");
//
//		textArea.addEventHandler(KeyEvent.KEY_PRESSED, ev -> {
//			if (ev.isControlDown() && ev.getCode() == KeyCode.SPACE) {
//
//				Bounds blankBounds = textArea.getBlankBounds();
//				Bounds localToScreen = textArea.localToScreen(blankBounds);
//
//				double minX = localToScreen.getMinX();
//				double minY = localToScreen.getMinY();
//				PopOver popOver = new PopOver(new Label("asdasdasd"));
//				popOver.show(textArea, minX, minY);
//			}
//		});
//		primaryStage.setScene(new Scene(textArea));
//		primaryStage.show();
//	}
@Override
public void start(Stage primaryStage) throws Exception {
    CodeArea textArea = new CodeArea("select * from ");
    new ASTSqlCodeAreaHelper(textArea, () -> {
        try {
            return DbUtil.getConnection();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    });
    //		//		UnaryOperator<Point2D> unaryOperator = textArea.popupAnchorAdjustmentProperty().get();
    //		//		unaryOperator.
    //		TableOpenResourceView tableOpenResourceView = new TableOpenResourceView(() -> {
    //			try {
    //				return DbUtil.getConnection();
    //			} catch (Exception e) {
    //				e.printStackTrace();
    //			}
    //			return null;
    //		}) {
    //
    //			/* (non-Javadoc)
    //			 * @see com.kyj.fx.voeditor.visual.component.popup.TableOpenResourceView#close()
    //			 */
    //			@Override
    //			public void close() {
    //
    //				ResultDialog<Map<String, Object>> result = getResult();
    //
    //				Map<String, Object> data = result.getData();
    //				if (data == null)
    //					return;
    //				Object object = data.get("table_name");
    //				if (object == null)
    //					return;
    //
    //				String string = currentPragraph(textArea);
    //				int markTextColumnIndex = getIndexOfValideWhiteSpace(string);
    //
    //				Paragraph<Collection<String>> currentParagraphRange = currentParagraphRange(textArea);
    //				IndexRange styleRangeAtPosition = currentParagraphRange.getStyleRangeAtPosition(markTextColumnIndex);
    //				IndexRange normalize = IndexRange.normalize(markTextColumnIndex, styleRangeAtPosition.getEnd());
    //				textArea.replaceText(normalize, object.toString());
    //
    //				super.close();
    //				textArea.getPopupWindow().hide();
    //
    //			}
    //
    //		};
    //
    //		textArea.setPopupWindow(new PopOver(tableOpenResourceView.getView()));
    //		textArea.setPopupAlignment(PopupAlignment.SELECTION_TOP_CENTER);
    //		textArea.addEventHandler(KeyEvent.KEY_PRESSED, ev -> {
    //
    //			if (ev.isControlDown() && ev.getCode() == KeyCode.SPACE) {
    //
    //				String string = markText(textArea);
    //				tableOpenResourceView.getView().getTxtFilter().setText(string);
    //
    //				textArea.getPopupWindow().show(primaryStage);
    //				textArea.getPopupWindow().requestFocus();
    //
    //				tableOpenResourceView.getView().getTxtFilter().requestFocus();
    //				tableOpenResourceView.getView().getTxtFilter().selectEnd();
    //			}
    //		});
    primaryStage.setScene(new Scene(textArea));
    primaryStage.show();
}
Also used : ASTSqlCodeAreaHelper(com.kyj.fx.voeditor.visual.component.text.ASTSqlCodeAreaHelper) Scene(javafx.scene.Scene) CodeArea(org.fxmisc.richtext.CodeArea)

Example 4 with CodeArea

use of org.fxmisc.richtext.CodeArea in project Gargoyle by callakrsos.

the class PagedCodeAreaFindAndReplaceHelper method findReplaceEvent.

/**
	 * 찾기 바꾸기 이벤트
	 *
	 * @작성자 : KYJ
	 * @작성일 : 2016. 10. 13.
	 * @param e
	 */
protected void findReplaceEvent(Event e) {
    if (e.isConsumed())
        return;
    SimpleTextView currentPageView = view.getCurrentPageView();
    CodeArea codeArea = currentPageView.getCodeArea();
    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) CodeArea(org.fxmisc.richtext.CodeArea)

Example 5 with CodeArea

use of org.fxmisc.richtext.CodeArea in project Gargoyle by callakrsos.

the class PagedCodeAreaFindAndReplaceHelper method setContent.

public void setContent(int start, int end, String text) {
    SimpleTextView currentPageView = this.view.getCurrentPageView();
    if (currentPageView != null) {
        CodeArea codeArea = currentPageView.getCodeArea();
        codeArea.getUndoManager().mark();
        codeArea.replaceText(start, end, text);
        codeArea.getUndoManager().mark();
    }
}
Also used : CodeArea(org.fxmisc.richtext.CodeArea)

Aggregations

CodeArea (org.fxmisc.richtext.CodeArea)6 Beta (com.google.common.annotations.Beta)1 TextSearchAndReplaceView (com.kyj.fx.voeditor.visual.component.popup.TextSearchAndReplaceView)1 ASTSqlCodeAreaHelper (com.kyj.fx.voeditor.visual.component.text.ASTSqlCodeAreaHelper)1 HOGMLexer (com.sri.ai.praise.model.v1.hogm.antlr.HOGMLexer)1 HOGMTerminalSymbols (com.sri.ai.praise.model.v1.hogm.antlr.HOGMTerminalSymbols)1 FXUtil (com.sri.ai.praise.sgsolver.demo.FXUtil)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 FXML (javafx.fxml.FXML)1 Scene (javafx.scene.Scene)1 IndexRange (javafx.scene.control.IndexRange)1 AnchorPane (javafx.scene.layout.AnchorPane)1 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 Token (org.antlr.v4.runtime.Token)1 LineNumberFactory (org.fxmisc.richtext.LineNumberFactory)1 StyleSpans (org.fxmisc.richtext.StyleSpans)1 StyleSpansBuilder (org.fxmisc.richtext.StyleSpansBuilder)1 UndoManager (org.fxmisc.undo.UndoManager)1