javafx.beans.WeakInvalidationListener Java Examples

The following examples show how to use javafx.beans.WeakInvalidationListener. 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: VariableHighlighter.java    From milkman with MIT License 7 votes vote down vote up
public HighLightRectangle(Node node) {
            if (node instanceof Text){
                Text text = (Text) node;
                listener = observable -> clear(node);
                text.textProperty().addListener(new WeakInvalidationListener(listener));
                text.localToSceneTransformProperty().addListener(new WeakInvalidationListener(listener));
            }
            if (node instanceof CodeArea){
                CodeArea codeArea = (CodeArea) node;
                listener = observable -> clear(node);
                codeArea.addEventFilter(ScrollEvent.ANY, evt -> listener.invalidated(null));
                codeArea.localToSceneTransformProperty().addListener(new WeakInvalidationListener(listener));
                codeArea.textProperty().addListener(new WeakInvalidationListener(listener));

//                codeArea.textProperty().addListener((obs, o, n) -> System.out.println("test"));
//                var parent = (VirtualizedScrollPane) codeArea.getParent();
//                parent.onScrollProperty().addListener(new WeakInvalidationListener(listener));
//                parent.localToSceneTransformProperty().addListener(new WeakInvalidationListener(listener));
//                parent.addEventFilter(ScrollEvent.ANY, evt -> listener.invalidated(null));

            }
        }
 
Example #2
Source File: TabCellTest.java    From WorkbenchFX with Apache License 2.0 6 votes vote down vote up
@Test
void testSettingItemNotNullWithSelectionStripNotNull() {
  robot.interact(() -> {
    tabCell.setSelectionStrip(mockStrip);
    tabCell.setItem(mockModule);
  });

  assertEquals("", tabCell.getText());
  assertEquals(mockTab, tabCell.getGraphic());
  assertTrue(tabCell.getStyleClass().contains(firstChild));

  verify(mockStrip, times(2)).getSelectedItem();
  verify(mockStrip).selectedItemProperty();
  verify(mockModule).getWorkbench();
  verify(mockBench).getTabFactory();
  verify(mockFactory).call(mockBench);
  verify(mockTab).setModule(mockModule);
  verify(mockProperty).addListener((WeakInvalidationListener) any());
  verify(mockStrip).getItems();
  verify(mockList).get(0);
}
 
Example #3
Source File: TabCellTest.java    From WorkbenchFX with Apache License 2.0 6 votes vote down vote up
@Test
void testSettingItemNullWithSelectionStripNotNull() {
  robot.interact(() -> {
    tabCell.setSelectionStrip(mockStrip);
    tabCell.setItem(null);
  });

  assertEquals("", tabCell.getText());
  assertNull(tabCell.getGraphic());
  assertFalse(tabCell.getStyleClass().contains(firstChild));

  verify(mockStrip).getSelectedItem();
  verify(mockStrip).selectedItemProperty();
  verify(mockProperty).addListener((WeakInvalidationListener) any());
  verifyNoMoreInteractions(mockModule, mockBench, mockFactory, mockTab, mockStrip, mockList);
}
 
Example #4
Source File: JFXTreeCell.java    From JFoenix with Apache License 2.0 6 votes vote down vote up
public JFXTreeCell() {

        selectedPane.getStyleClass().add("selection-bar");
        selectedPane.setBackground(new Background(new BackgroundFill(Color.RED, CornerRadii.EMPTY, Insets.EMPTY)));
        selectedPane.setPrefWidth(3);
        selectedPane.setMouseTransparent(true);
        selectedProperty().addListener((o, oldVal, newVal) -> selectedPane.setVisible(newVal ? true : false));

        final InvalidationListener treeItemInvalidationListener = observable -> {
            TreeItem<T> oldTreeItem = treeItemRef == null ? null : treeItemRef.get();
            if (oldTreeItem != null) {
                oldTreeItem.graphicProperty().removeListener(weakTreeItemGraphicListener);
            }

            TreeItem<T> newTreeItem = getTreeItem();
            if (newTreeItem != null) {
                newTreeItem.graphicProperty().addListener(weakTreeItemGraphicListener);
                treeItemRef = new WeakReference<>(newTreeItem);
            }
        };
        final WeakInvalidationListener weakTreeItemListener = new WeakInvalidationListener(treeItemInvalidationListener);
        treeItemProperty().addListener(weakTreeItemListener);
        if (getTreeItem() != null) {
            getTreeItem().graphicProperty().addListener(weakTreeItemGraphicListener);
        }
    }
 
Example #5
Source File: MapTile.java    From maps with GNU General Public License v3.0 5 votes vote down vote up
MapTile(BaseMap baseMap, int nearestZoom, long i, long j) {
        this.baseMap = baseMap;
        this.myZoom = nearestZoom;
        this.i = i;
        this.j = j;
        scale.setPivotX(0);
        scale.setPivotY(0);
        getTransforms().add(scale);
        debug("[JVDBG] load image [" + myZoom + "], i = " + i + ", j = " + j);

        ImageView imageView = new ImageView();
        imageView.setMouseTransparent(true);
        Image tile = TILE_RETRIEVER.loadTile(myZoom, i, j);
        imageView.setImage(tile);
        this.progress = tile.progressProperty();

//        Label l = new Label("Tile [" + myZoom + "], i = " + i + ", j = " + j);
        getChildren().addAll(imageView);//,l);
        this.progress.addListener(new InvalidationListener() {
            @Override
            public void invalidated(Observable observable) {
                if (progress.get() >= 1.0d) {
                    debug("[JVDBG] got image [" + myZoom + "], i = " + i + ", j = " + j);
                    setNeedsLayout(true);
                    progress.removeListener(this);
                }
            }
        });
        baseMap.zoom().addListener(new WeakInvalidationListener(zl));
        baseMap.translateXProperty().addListener(new WeakInvalidationListener(zl));
        baseMap.translateYProperty().addListener(new WeakInvalidationListener(zl));
        calculatePosition();
        this.setMouseTransparent(true);
    }
 
Example #6
Source File: PreviewStyledTextArea.java    From markdown-writer-fx with BSD 2-Clause "Simplified" License 5 votes vote down vote up
PreviewStyledTextArea() {
	setEditable(false);
	setFocusTraversable(false);
	getStyleClass().add("padding");
	setUndoManager(UndoManagerFactory.zeroHistorySingleChangeUM(richChanges()));

	updateFont();

	optionsListener = e -> updateFont();
	WeakInvalidationListener weakOptionsListener = new WeakInvalidationListener(optionsListener);
	Options.fontFamilyProperty().addListener(weakOptionsListener);
	Options.fontSizeProperty().addListener(weakOptionsListener);
}
 
Example #7
Source File: JFXHighlighter.java    From JFoenix with Apache License 2.0 4 votes vote down vote up
public HighLightRectangle(Text text) {
    listener = observable -> clear(text);
    text.textProperty().addListener(new WeakInvalidationListener(listener));
    text.localToSceneTransformProperty().addListener(new WeakInvalidationListener(listener));
}
 
Example #8
Source File: MarkdownEditorPane.java    From markdown-writer-fx with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public MarkdownEditorPane() {
	textArea = new MarkdownTextArea();
	textArea.setWrapText(true);
	textArea.setUseInitialStyleForInsertion(true);
	textArea.getStyleClass().add("markdown-editor");
	textArea.getStylesheets().add("org/markdownwriterfx/editor/MarkdownEditor.css");
	textArea.getStylesheets().add("org/markdownwriterfx/prism.css");

	textArea.textProperty().addListener((observable, oldText, newText) -> {
		textChanged(newText);
	});

	textArea.addEventHandler(ContextMenuEvent.CONTEXT_MENU_REQUESTED, this::showContextMenu);
	textArea.addEventHandler(MouseEvent.MOUSE_PRESSED, this::hideContextMenu);
	textArea.setOnDragEntered(this::onDragEntered);
	textArea.setOnDragExited(this::onDragExited);
	textArea.setOnDragOver(this::onDragOver);
	textArea.setOnDragDropped(this::onDragDropped);

	smartEdit = new SmartEdit(this, textArea);

	Nodes.addInputMap(textArea, sequence(
		consume(keyPressed(PLUS, SHORTCUT_DOWN),	this::increaseFontSize),
		consume(keyPressed(MINUS, SHORTCUT_DOWN),	this::decreaseFontSize),
		consume(keyPressed(DIGIT0, SHORTCUT_DOWN),	this::resetFontSize),
		consume(keyPressed(W, ALT_DOWN),			this::showWhitespace),
		consume(keyPressed(I, ALT_DOWN),			this::showImagesEmbedded)
	));

	// create scroll pane
	VirtualizedScrollPane<MarkdownTextArea> scrollPane = new VirtualizedScrollPane<>(textArea);

	// create border pane
	borderPane = new BottomSlidePane(scrollPane);

	overlayGraphicFactory = new ParagraphOverlayGraphicFactory(textArea);
	textArea.setParagraphGraphicFactory(overlayGraphicFactory);
	updateFont();
	updateShowLineNo();
	updateShowWhitespace();

	// initialize properties
	markdownText.set("");
	markdownAST.set(parseMarkdown(""));

	// find/replace
	findReplacePane = new FindReplacePane(textArea);
	findHitsChangeListener = this::findHitsChanged;
	findReplacePane.addListener(findHitsChangeListener);
	findReplacePane.visibleProperty().addListener((ov, oldVisible, newVisible) -> {
		if (!newVisible)
			borderPane.setBottom(null);
	});

	// listen to option changes
	optionsListener = e -> {
		if (textArea.getScene() == null)
			return; // editor closed but not yet GCed

		if (e == Options.fontFamilyProperty() || e == Options.fontSizeProperty())
			updateFont();
		else if (e == Options.showLineNoProperty())
			updateShowLineNo();
		else if (e == Options.showWhitespaceProperty())
			updateShowWhitespace();
		else if (e == Options.showImagesEmbeddedProperty())
			updateShowImagesEmbedded();
		else if (e == Options.markdownRendererProperty() || e == Options.markdownExtensionsProperty()) {
			// re-process markdown if markdown extensions option changes
			parser = null;
			textChanged(textArea.getText());
		}
	};
	WeakInvalidationListener weakOptionsListener = new WeakInvalidationListener(optionsListener);
	Options.fontFamilyProperty().addListener(weakOptionsListener);
	Options.fontSizeProperty().addListener(weakOptionsListener);
	Options.markdownRendererProperty().addListener(weakOptionsListener);
	Options.markdownExtensionsProperty().addListener(weakOptionsListener);
	Options.showLineNoProperty().addListener(weakOptionsListener);
	Options.showWhitespaceProperty().addListener(weakOptionsListener);
	Options.showImagesEmbeddedProperty().addListener(weakOptionsListener);

	// workaround a problem with wrong selection after undo:
	//   after undo the selection is 0-0, anchor is 0, but caret position is correct
	//   --> set selection to caret position
	textArea.selectionProperty().addListener((observable,oldSelection,newSelection) -> {
		// use runLater because the wrong selection temporary occurs while edition
		Platform.runLater(() -> {
			IndexRange selection = textArea.getSelection();
			int caretPosition = textArea.getCaretPosition();
			if (selection.getStart() == 0 && selection.getEnd() == 0 && textArea.getAnchor() == 0 && caretPosition > 0)
				textArea.selectRange(caretPosition, caretPosition);
		});
	});
}