Java Code Examples for javafx.scene.Node#equals()

The following examples show how to use javafx.scene.Node#equals() . 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: DefaultListCell.java    From Quelea with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void updateItem(T item, boolean empty) {
    super.updateItem(item, empty);

    if(empty) {
        setText(null);
        setGraphic(null);
    }
    else if(item instanceof Node) {
        setText(null);
        Node currentNode = getGraphic();
        Node newNode = (Node) item;
        if(currentNode == null || !currentNode.equals(newNode)) {
            setGraphic(newNode);
        }
    }
    else {
        setText(item == null ? "null" : item.toString());
        setGraphic(null);
    }
}
 
Example 2
Source File: SimpleListViewScrollSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private static <T> ListCell<T> createDefaultCellImpl() {
    return new ListCell<T>() {
        @Override
        public void updateItem(T item, boolean empty) {
            super.updateItem(item, empty);

            if (empty) {
                setText(null);
                setGraphic(null);
            } else if (item instanceof Node) {
                setText(null);
                Node currentNode = getGraphic();
                Node newNode = (Node) item;
                if (currentNode == null || !currentNode.equals(newNode)) {
                    setGraphic(newNode);
                }
            } else {
                /**
                 * This label is used if the item associated with this
                 * cell is to be represented as a String. While we will
                 * lazily instantiate it we never clear it, being more
                 * afraid of object churn than a minor "leak" (which
                 * will not become a "major" leak).
                 */
                setText(item == null ? "null" : item.toString());
                setGraphic(null);
            }
        }
    };
}
 
Example 3
Source File: JFXComboBox.java    From JFoenix with Apache License 2.0 5 votes vote down vote up
private boolean updateDisplayText(ListCell<T> cell, T item, boolean empty) {
    if (empty) {
        // create empty cell
        if (cell == null) {
            return true;
        }
        cell.setGraphic(null);
        cell.setText(null);
        return true;
    } else if (item instanceof Node) {
        Node currentNode = cell.getGraphic();
        Node newNode = (Node) item;
        //  create a node from the selected node of the listview
        //  using JFXComboBox {@link #nodeConverterProperty() NodeConverter})
        NodeConverter<T> nc = this.getNodeConverter();
        Node node = nc == null ? null : nc.toNode(item);
        if (currentNode == null || !currentNode.equals(newNode)) {
            cell.setText(null);
            cell.setGraphic(node == null ? newNode : node);
        }
        return node == null;
    } else {
        // run item through StringConverter if it isn't null
        StringConverter<T> c = this.getConverter();
        String s = item == null ? this.getPromptText() : (c == null ? item.toString() : c.toString(item));
        cell.setText(s);
        cell.setGraphic(null);
        return s == null || s.isEmpty();
    }
}
 
Example 4
Source File: TargetEditorController.java    From ShootOFF with GNU General Public License v3.0 4 votes vote down vote up
public void regionClicked(MouseEvent event) {
	if (!cursorButton.isSelected()) {
		// We want to drop a new region
		regionDropped(event);
		return;
	}

	// Want to select the current region
	final Node selected = (Node) event.getTarget();
	boolean tagEditorOpen = false;

	if (tagEditor.isPresent()) {
		// Close tag editor
		tagsButton.setSelected(false);
		toggleTagEditor();
		tagEditorOpen = true;
	}

	if (cursorRegion.isPresent()) {
		final Node previous = cursorRegion.get();

		// Unhighlight the old selection
		if (!previous.equals(selected)) {
			unhighlightRegion(previous);
		}
	}

	if (((TargetRegion) selected).getType() != RegionType.IMAGE)
		((Shape) selected).setStroke(TargetRegion.SELECTED_STROKE_COLOR);
	selected.requestFocus();
	toggleShapeControls(true);
	cursorRegion = Optional.of(selected);
	if (((TargetRegion) selected).getType() != RegionType.IMAGE)
		regionColorChoiceBox.getSelectionModel().select(getColorName((Color) ((Shape) selected).getFill()));

	// Re-open editor
	if (tagEditorOpen) {
		tagsButton.setSelected(true);
		toggleTagEditor();
	}
}