org.fxmisc.richtext.event.MouseOverTextEvent Java Examples

The following examples show how to use org.fxmisc.richtext.event.MouseOverTextEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ErrorHandling.java    From Recaf with MIT License 6 votes vote down vote up
/**
 * Marks the given range with the <i>"error"</i> type.
 *
 * @param line
 * 		Line the problem occured on.
 * @param from
 * 		Relative start position on line.
 * @param to
 * 		Relative end position on line.
 * @param literalFrom
 * 		Literal start position in string.
 * @param message
 * 		Message to supply pop-up window with.
 */
protected void markProblem(int line, int from, int to, int literalFrom, String message) {
	// Highlight the line & add the error indicator next to the line number
	Platform.runLater(() ->
			codeArea.setStyle(line, from, to, Collections.singleton("error"))
	);
	// Add tooltips to highlighted region
	Tooltip popup = new Tooltip(message);
	codeArea.addEventHandler(MouseOverTextEvent.MOUSE_OVER_TEXT_BEGIN, e -> {
		int charPos = e.getCharacterIndex();
		if(charPos >= literalFrom && charPos <= literalFrom + (to - from)) {
			Point2D pos = e.getScreenPosition();
			popup.show(codeArea, pos.getX(), pos.getY() + 10);
		}
	});
	codeArea.addEventHandler(MouseOverTextEvent.MOUSE_OVER_TEXT_END, e -> popup.hide());
}
 
Example #2
Source File: NodeEditionCodeArea.java    From pmd-designer with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * TODO does this need to be disableable? Maybe some keyboards use the CTRL key in ways I don't
 */
private void enableCtrlSelection() {

    final Val<Boolean> isNodeSelectionMode =
        ReactfxUtil.vetoableYes(getDesignerRoot().isCtrlDownProperty(), CTRL_SELECTION_VETO_PERIOD);

    addEventHandler(
        MouseOverTextEvent.MOUSE_OVER_TEXT_BEGIN,
        ev -> {
            if (!isNodeSelectionMode.getValue()) {
                return;
            }
            Node currentRoot = getService(DesignerRoot.AST_MANAGER).compilationUnitProperty().getValue();
            if (currentRoot == null) {
                return;
            }

            TextPos2D target = getPmdLineAndColumnFromOffset(this, ev.getCharacterIndex());

            findNodeAt(currentRoot, target)
                .map(n -> NodeSelectionEvent.of(n, new DataHolder().withData(CARET_POSITION, target)))
                .ifPresent(selectionEvts::push);
        }
    );


    isNodeSelectionMode.values().distinct().subscribe(isSelectionMode -> {
        pseudoClassStateChanged(PseudoClass.getPseudoClass("is-node-selection"), isSelectionMode);
        setMouseOverTextDelay(isSelectionMode ? NODE_SELECTION_HOVER_DELAY : null);
    });
}
 
Example #3
Source File: ErrorHandling.java    From Recaf with MIT License 5 votes vote down vote up
/**
 * This is cancer, but it works flawlessly. Tracking the handlers also sucks.
 */
protected void clearOldEvents() {
	try {
		Object handlerManager = ((NodeEventDispatcher)codeArea.getEventDispatcher()).getEventHandlerManager();
		Field handlerMap  = EventHandlerManager.class.getDeclaredField("eventHandlerMap");
		handlerMap.setAccessible(true);
		Map map = (Map) handlerMap.get(handlerManager);
		map.remove(MouseOverTextEvent.MOUSE_OVER_TEXT_BEGIN);
		map.remove(MouseOverTextEvent.MOUSE_OVER_TEXT_END);
	} catch(Exception exx) {
		exx.printStackTrace();
	}
}
 
Example #4
Source File: JavaDocHandling.java    From Recaf with MIT License 5 votes vote down vote up
/**
 * @param pane
 * 		Pane to handle JavaDoc on.
 * @param controller
 * 		Controller to pull docs from.
 * @param code
 * 		Analyzed code.
 */
public JavaDocHandling(JavaEditorPane pane, GuiController controller, SourceCode code) {
	this.pane = pane;
	// Fetch the solver so we can call it manually (see below for why)
	Optional<SymbolResolver> optSolver = controller.getWorkspace().getSourceParseConfig().getSymbolResolver();
	if (!optSolver.isPresent())
		throw new IllegalStateException("");
	this.solver = optSolver.get();
	this.code = code;
	// Set mouse-over event
	pane.codeArea.addEventHandler(MouseOverTextEvent.MOUSE_OVER_TEXT_BEGIN, e -> {
		last = e.getScreenPosition();
		// Get node from event position
		int charPos = e.getCharacterIndex();
		TwoDimensional.Position pos = pane.codeArea.offsetToPosition(charPos,
				TwoDimensional.Bias.Backward);
		// So the problem with "getSelection" is that internally it will resolve to the ACTUAL
		// proper descriptor... but in the JavaDocs, if we have generics, we can have a return type "T"
		// but in the descriptor it really is "java/lang/Object".
		Object selection = getSelection(pos);
		if(selection instanceof ClassSelection) {
			handleClassType(controller, (ClassSelection) selection);
		} else if(selection instanceof MemberSelection) {
			MemberSelection member = (MemberSelection) selection;
			if (member.method())
				handleMethodType(controller, member);
			else
				handleFieldType(controller, member);
		}
	});
}
 
Example #5
Source File: TooltipDemo.java    From RichTextFX with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void start(Stage stage) {
    StyleClassedTextArea area = new StyleClassedTextArea();
    area.setWrapText(true);
    area.appendText("Pause the mouse over the text for 1 second.");

    Popup popup = new Popup();
    Label popupMsg = new Label();
    popupMsg.setStyle(
            "-fx-background-color: black;" +
            "-fx-text-fill: white;" +
            "-fx-padding: 5;");
    popup.getContent().add(popupMsg);

    area.setMouseOverTextDelay(Duration.ofSeconds(1));
    area.addEventHandler(MouseOverTextEvent.MOUSE_OVER_TEXT_BEGIN, e -> {
        int chIdx = e.getCharacterIndex();
        Point2D pos = e.getScreenPosition();
        popupMsg.setText("Character '" + area.getText(chIdx, chIdx+1) + "' at " + pos);
        popup.show(area, pos.getX(), pos.getY() + 10);
    });
    area.addEventHandler(MouseOverTextEvent.MOUSE_OVER_TEXT_END, e -> {
        popup.hide();
    });

    Scene scene = new Scene(area, 600, 400);
    stage.setScene(scene);
    stage.setTitle("Tooltip Demo");
    stage.show();
}
 
Example #6
Source File: MouseOverTextDelayTests.java    From RichTextFX with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void start(Stage stage) throws Exception {
    super.start(stage);

    area.addEventHandler(MouseOverTextEvent.MOUSE_OVER_TEXT_BEGIN, e -> beginFired.set(true));
    area.addEventHandler(MouseOverTextEvent.MOUSE_OVER_TEXT_END,   e -> endFired.set(true));

    area.replaceText("a long line of some example text");

    resetBegin();
    resetEnd();

    // insure mouse is off of area
    moveMouseOutsideOfArea();
}
 
Example #7
Source File: GenericStyledArea.java    From RichTextFX with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private EventStream<MouseOverTextEvent> mouseOverTextEvents(ObservableSet<ParagraphBox<PS, SEG, S>> cells, Duration delay) {
    return merge(cells, c -> c.stationaryIndices(delay).map(e -> e.unify(
            l -> l.map((pos, charIdx) -> MouseOverTextEvent.beginAt(c.localToScreen(pos), getParagraphOffset(c.getIndex()) + charIdx)),
            r -> MouseOverTextEvent.end())));
}