Java Code Examples for javafx.scene.Node

The following examples show how to use javafx.scene.Node. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: marathonv5   Source File: ModalDialog.java    License: Apache License 2.0 6 votes vote down vote up
private ObservableList<Node> getChildren(Node node) {
    if (node instanceof ButtonBar) {
        return ((ButtonBar) node).getButtons();
    }
    if (node instanceof ToolBar) {
        return ((ToolBar) node).getItems();
    }
    if (node instanceof Pane) {
        return ((Pane) node).getChildren();
    }
    if (node instanceof TabPane) {
        ObservableList<Node> contents = FXCollections.observableArrayList();
        ObservableList<Tab> tabs = ((TabPane) node).getTabs();
        for (Tab tab : tabs) {
            contents.add(tab.getContent());
        }
        return contents;
    }
    return FXCollections.observableArrayList();
}
 
Example 2
@Override
protected void updateItem(File item, boolean empty) {
	super.updateItem(item, empty);

	// add/remove separator below "open folder" item
	if (!empty && item == OPEN_FOLDER && ProjectsComboBox.this.getItems().size() > 1)
		getStyleClass().add("open-project");
	else
		getStyleClass().remove("open-project");

	String text = null;
	Node graphic = null;
	if (!empty && item != null) {
		text = (item == OPEN_FOLDER)
			? Messages.get("ProjectsComboBox.openProject")
			: item.getAbsolutePath();

		graphic = closeButton;
		closeButton.setVisible(item != OPEN_FOLDER);
	}
	setText(text);
	setGraphic(graphic);
}
 
Example 3
Source Project: AsciidocFX   Source File: CellUtils.java    License: Apache License 2.0 6 votes vote down vote up
static <T> void startEdit(final Cell<T> cell,
                          final StringConverter<T> converter,
                          final HBox hbox,
                          final Node graphic,
                          final TextField textField) {
    if (textField != null) {
        textField.setText(getItemText(cell, converter));
    }
    cell.setText(null);

    if (graphic != null) {
        hbox.getChildren().setAll(graphic, textField);
        cell.setGraphic(hbox);
    } else {
        cell.setGraphic(textField);
    }

    textField.selectAll();

    // requesting focus so that key input can immediately go into the
    // TextField (see RT-28132)
    textField.requestFocus();
}
 
Example 4
Source Project: pdfsam   Source File: DashboardTile.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
public DashboardTile(String title, String description, Node graphic) {
    getStyleClass().addAll("dashboard-modules-tile");
    Label titleLabel = new Label(title);
    titleLabel.getStyleClass().add("dashboard-modules-tile-title");
    if (nonNull(graphic)) {
        titleLabel.setGraphic(graphic);
    }
    Label textLabel = new Label(description);
    textLabel.getStyleClass().add("dashboard-modules-tile-text");
    textLabel.setMinHeight(USE_PREF_SIZE);
    VBox topTile = new VBox(5);
    topTile.getChildren().addAll(titleLabel, textLabel);

    button.getStyleClass().add("dashboard-modules-invisible-button");
    button.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);

    armed.bind(button.armedProperty());
    getChildren().addAll(new StackPane(topTile, button));
    setMaxHeight(USE_PREF_SIZE);
    setMinHeight(USE_PREF_SIZE);
}
 
Example 5
Source Project: kafka-message-tool   Source File: MainApplicationController.java    License: MIT License 6 votes vote down vote up
public MainApplicationController(Stage mainStage,
                                 DataModel model,
                                 Application fxApplication,
                                 ApplicationSettings appSettings,
                                 Node loggingPaneArea,
                                 ControllerRepositoryFactory controllersRepositoryFactory,
                                 DefaultActionHandlerFactory actionHandlerFactory,
                                 ApplicationBusySwitcher busySwitcher) {
    appStage = mainStage;
    dataModel = model;
    this.fxApplication = fxApplication;
    this.appSettings = appSettings;
    this.loggingPaneArea = loggingPaneArea;
    this.controllersRepositoryFactory = controllersRepositoryFactory;
    this.actionHandlerFactory = actionHandlerFactory;
    this.busySwitcher = busySwitcher;
}
 
Example 6
Source Project: FxDock   Source File: FxDockTabPane.java    License: Apache License 2.0 6 votes vote down vote up
protected Tab newTab(Node nd)
{
	Node n = DockTools.prepareToAdd(nd);
		
	Tab t = new Tab(null, n);
	if(n instanceof FxDockPane)
	{
		FxDockPane p = (FxDockPane)n;
		t.setGraphic(p.titleField);
		t.setOnClosed((ev) -> 
		{
			Node pp = DockTools.getParent(this);
			DockTools.collapseEmptySpace(pp);
		});
	}
	return t;
}
 
Example 7
Source Project: phoebus   Source File: SendLogbookAction.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private void submitLogEntry(final Node parent, final String title, final String body, final File image_file)
{
    LogEntryBuilder logEntryBuilder = new LogEntryBuilder();
    if (title != null)
        logEntryBuilder.title(title);
    if (body != null)
        logEntryBuilder.appendDescription(body);

    if (image_file != null)
    {
        try
        {
            final Attachment attachment = AttachmentImpl.of(image_file, "image", false);
            logEntryBuilder.attach(attachment);
        }
        catch (FileNotFoundException ex)
        {
            logger.log(Level.WARNING, "Cannot attach " + image_file, ex);
        }
    }

    final LogEntryModel model = new LogEntryModel(logEntryBuilder.createdDate(Instant.now()).build());

    new LogEntryEditorStage(parent, model, null).show();

}
 
Example 8
default Node createGui(Stage stage, T value, Consumer<T> onAction) {
	TextField valueField = new TextField(toString(value));
	
	Runnable updateValue = () -> {
		String newValue = valueField.getText();
		if(!newValue.equals(value)) {
			try {
				onAction.accept(parse(newValue));
			} catch(Exception exc) {
				exc.printStackTrace();
				valueField.setText(toString(value));
			}
		}
	};
	
	valueField.setOnAction(event -> updateValue.run());
	valueField.focusedProperty().addListener((observable, oldValue, newValue) -> {
		if(!newValue) {
			updateValue.run();
		}
	});
	return valueField;
}
 
Example 9
Source Project: JFoenix   Source File: JFXNodesList.java    License: Apache License 2.0 5 votes vote down vote up
private static Object getConstraint(Node node, Object key) {
    if (node.hasProperties()) {
        Object value = node.getProperties().get(key);
        if (value != null) {
            return value;
        }
    }
    return null;
}
 
Example 10
private Node createErrorNode() {
	Polyline errorNode = new Polyline(
		0, 0,  ERROR_SIZE, 0,  ERROR_SIZE, ERROR_SIZE,  0, ERROR_SIZE,  0, 0,	// rectangle
		ERROR_SIZE, ERROR_SIZE,  0, ERROR_SIZE,  ERROR_SIZE, 0);				// cross
	errorNode.setStroke(Color.RED); //TODO use CSS
	return errorNode;
}
 
Example 11
Source Project: jmonkeybuilder   Source File: PaintingComponentContainer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Activate the selected painting component.
 *
 * @param observable the component box's property.
 * @param oldValue   the previous component.
 * @param newValue   the new component.
 */
@FxThread
private void activate(
        @NotNull ObservableValue<? extends PaintingComponent> observable,
        @Nullable PaintingComponent oldValue,
        @Nullable PaintingComponent newValue
) {

    var items = getContainer().getChildren();

    if (oldValue != null) {
        oldValue.notifyHided();
        oldValue.stopPainting();
        items.remove(oldValue);
    }

    var paintedObject = getPaintedObject();

    if (newValue != null) {

        if (paintedObject != null) {
            newValue.startPainting(paintedObject);
        }

        if (isShowed()) {
            newValue.notifyShowed();
        }

        items.add((Node) newValue);
    }

    setCurrentComponent(newValue);
}
 
Example 12
Source Project: AsciidocFX   Source File: AwesomeService.java    License: Apache License 2.0 5 votes vote down vote up
public Node getIcon(final Path path) {

        FontIcon fontIcon = new FontIcon(FontAwesome.FILE_O);

        if (Files.isDirectory(path)) {
            fontIcon.setIconCode(FontAwesome.FOLDER_O);
        } else {
            if (pathResolver.isAsciidoc(path) || pathResolver.isMarkdown(path))
                fontIcon.setIconCode(FontAwesome.FILE_TEXT_O);
            if (pathResolver.isXML(path) || pathResolver.isCode(path))
                fontIcon.setIconCode(FontAwesome.FILE_CODE_O);
            if (pathResolver.isImage(path))
                fontIcon.setIconCode(FontAwesome.FILE_PICTURE_O);
            if (pathResolver.isPDF(path))
                fontIcon.setIconCode(FontAwesome.FILE_PDF_O);
            if (pathResolver.isHTML(path))
                fontIcon.setIconCode(FontAwesome.HTML5);
            if (pathResolver.isArchive(path))
                fontIcon.setIconCode(FontAwesome.FILE_ZIP_O);
            if (pathResolver.isExcel(path))
                fontIcon.setIconCode(FontAwesome.FILE_EXCEL_O);
            if (pathResolver.isVideo(path))
                fontIcon.setIconCode(FontAwesome.FILE_VIDEO_O);
            if (pathResolver.isWord(path))
                fontIcon.setIconCode(FontAwesome.FILE_WORD_O);
            if (pathResolver.isPPT(path))
                fontIcon.setIconCode(FontAwesome.FILE_POWERPOINT_O);
            if (pathResolver.isBash(path))
                fontIcon.setIconCode(FontAwesome.TERMINAL);
        }

        return new Label(null, fontIcon);
    }
 
Example 13
Source Project: logbook-kai   Source File: FleetTabPane.java    License: MIT License 5 votes vote down vote up
/**
 * 注釈プラグインの初期化
 */
private void initializeRemarkPlugin() {
    for (Updateable<DeckPort> plugin : Plugin.getContent(FleetTabRemark.class)) {
        Node node;
        if (plugin instanceof Node) {
            node = ((Node) plugin);
        } else {
            node = new RemarkLabel(plugin);
        }
        this.remark.getChildren().add(node);
    }
}
 
Example 14
Source Project: gef   Source File: SelectionModel.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void onChanged(
		javafx.collections.MapChangeListener.Change<? extends Node, ? extends IVisualPart<? extends Node>> change) {
	// keep model in sync with part hierarchy
	if (change.wasRemoved()) {
		IVisualPart<? extends Node> valueRemoved = change
				.getValueRemoved();
		if (selection.contains(valueRemoved)) {
			selection.remove(valueRemoved);
		}
	}
}
 
Example 15
Source Project: java-ml-projects   Source File: AppUtils.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
public static void disableIfNotSelected(SelectionModel selectionModel, Node... nodes) {
	BooleanBinding selected = selectionModel.selectedItemProperty().isNull();
	for (Node node : nodes) {
		node.disableProperty().bind(selected);
	}
}
 
Example 16
Source Project: JFoenix   Source File: JFXAlertAnimation.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Animation createShowingAnimation(Node contentContainer, Node overlay) {
    return new CachedTransition(contentContainer, new Timeline(
        new KeyFrame(Duration.millis(1000),
            new KeyValue(contentContainer.scaleXProperty(), 1, Interpolator.EASE_OUT),
            new KeyValue(contentContainer.scaleYProperty(), 1, Interpolator.EASE_OUT),
            new KeyValue(overlay.opacityProperty(), 1, Interpolator.EASE_BOTH)
        ))) {
        {
            setCycleDuration(Duration.millis(160));
            setDelay(Duration.seconds(0));
        }
    };
}
 
Example 17
Source Project: JFoenix   Source File: JFXComboBox.java    License: 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 18
Source Project: ikonli   Source File: StackedFontIcon.java    License: Apache License 2.0 5 votes vote down vote up
private void setIconColorOnChildren(Paint color) {
    for (Node node : getChildren()) {
        if (node instanceof Icon) {
            ((Icon) node).setIconColor(color);
        }
    }
}
 
Example 19
Source Project: Flowless   Source File: CellWrapper.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static <T, N extends Node,C extends Cell<T, N>>
CellWrapper<T, N, C> beforeUpdateIndex(C cell, IntConsumer action) {
    return new CellWrapper<T, N, C>(cell) {
        @Override
        public void updateIndex(int index) {
            action.accept(index);
            super.updateIndex(index);
        }
    };
}
 
Example 20
Source Project: JFoenix   Source File: ValidatorBase.java    License: Apache License 2.0 5 votes vote down vote up
private void install(Node node, Tooltip tooltip) {
    if (tooltip == null) {
        return;
    }
    if (tooltip instanceof JFXTooltip) {
        JFXTooltip.install(node, (JFXTooltip) tooltip);
    } else {
        Tooltip.install(node, tooltip);
    }
}
 
Example 21
Source Project: gef   Source File: FocusModel.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void onChanged(
		javafx.collections.MapChangeListener.Change<? extends Node, ? extends IVisualPart<? extends Node>> change) {
	// keep model in sync with part hierarchy
	if (change.wasRemoved()) {
		if (focusedProperty.get() == change.getValueRemoved()) {
			setFocus(null);
		}
	}
}
 
Example 22
Source Project: marathonv5   Source File: SepiaToneSample.java    License: Apache License 2.0 5 votes vote down vote up
public static Node createIconContent() {
    ImageView iv = new ImageView(BOAT);
    iv.setFitWidth(80);
    iv.setFitHeight(80);
    iv.setViewport(new Rectangle2D(90,0,332,332));
    final SepiaTone SepiaTone = new SepiaTone();
    SepiaTone.setLevel(1);
    iv.setEffect(SepiaTone);
    return iv;
}
 
Example 23
Source Project: constellation   Source File: AttributeEditorPanel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void updateItem(Object item, boolean empty) {
    super.updateItem(item, empty);

    AbstractAttributeInteraction<?> interaction = AbstractAttributeInteraction.getInteraction(attrDataType);
    final String displayText;
    final List<Node> displayNodes;
    if (item == null) {
        displayText = NO_VALUE_TEXT;
        displayNodes = Collections.emptyList();
    } else {
        displayText = interaction.getDisplayText(item);
        displayNodes = interaction.getDisplayNodes(item, -1, CELL_HEIGHT - 1);
    }

    GridPane gridPane = new GridPane();
    gridPane.setHgap(CELL_ITEM_SPACING);
    ColumnConstraints displayNodeConstraint = new ColumnConstraints(CELL_HEIGHT - 1);
    displayNodeConstraint.setHalignment(HPos.CENTER);

    for (int i = 0; i < displayNodes.size(); i++) {
        final Node displayNode = displayNodes.get(i);
        gridPane.add(displayNode, i, 0);
        gridPane.getColumnConstraints().add(displayNodeConstraint);
    }

    setGraphic(gridPane);
    setPrefHeight(CELL_HEIGHT);
    setText(displayText);
}
 
Example 24
Source Project: gef   Source File: HoverGesture.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 *
 * @param viewer
 *            The {@link IViewer}.
 * @param hoverIntent
 *            The hover intent {@link Node}.
 */
protected void notifyHoverIntent(IViewer viewer, Node hoverIntent) {
	// determine hover policies
	Collection<? extends IOnHoverHandler> policies = getHandlerResolver()
			.resolve(HoverGesture.this, hoverIntent, viewer,
					ON_HOVER_POLICY_KEY);
	getDomain().openExecutionTransaction(HoverGesture.this);
	// active policies are unnecessary because hover is not a
	// gesture, just one event at one point in time
	for (IOnHoverHandler policy : policies) {
		policy.hoverIntent(hoverIntent);
	}
	getDomain().closeExecutionTransaction(HoverGesture.this);
}
 
Example 25
Source Project: MyBox   Source File: LabeledHorizontalBarChart.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void seriesRemoved(final Series<X, Y> series) {
    if (labelType != null && labelType != LabelType.NotDisplay && labelType != LabelType.Pop) {
        for (Node bar : nodeMap.keySet()) {
            Node text = nodeMap.get(bar);
            this.getPlotChildren().remove(text);
        }
        nodeMap.clear();
    }
    super.seriesRemoved(series);
}
 
Example 26
Source Project: marathonv5   Source File: StackPaneSample.java    License: Apache License 2.0 5 votes vote down vote up
public static Node createIconContent() {
    StackPane sp = new StackPane();

    Rectangle rectangle = new Rectangle(62, 62, Color.LIGHTGREY);
    rectangle.setStroke(Color.BLACK);
    sp.setPrefSize(rectangle.getWidth(), rectangle.getHeight());

    Rectangle biggerRec = new Rectangle(55, 55, Color.web("#1c89f4"));
    Rectangle smallerRec = new Rectangle(35, 35, Color.web("#349b00"));

    sp.getChildren().addAll(rectangle, biggerRec, smallerRec);
    return new Group(sp);
}
 
Example 27
Source Project: graph-editor   Source File: DraggableBox.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Gets the closest ancestor (e.g. parent, grandparent) to a node that is a subclass of {@link Region}.
 *
 * @param node a JavaFX {@link Node}
 * @return the node's closest ancestor that is a subclass of {@link Region}, or {@code null} if none exists
 */
private Region getContainer(final Node node) {

    final Parent parent = node.getParent();

    if (parent == null) {
        return null;
    } else if (parent instanceof Region) {
        return (Region) parent;
    } else {
        return getContainer(parent);
    }
}
 
Example 28
Source Project: bisq   Source File: InfoTextField.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
private void setActionHandlers(Node node) {

        currentIcon.setManaged(true);
        currentIcon.setVisible(true);

        // As we don't use binding here we need to recreate it on mouse over to reflect the current state
        currentIcon.setOnMouseEntered(e -> popoverWrapper.showPopOver(() -> createPopOver(node)));
        currentIcon.setOnMouseExited(e -> popoverWrapper.hidePopOver());
    }
 
Example 29
public static Node getRefIcon(GitRef ref) {
    if (ref instanceof GitTag) {
        return getIcon(Octicons.Glyph.TAG);
    } else if (ref instanceof GitBranch) {
        return getIcon(Octicons.Glyph.BRANCH);
    } else {
        return null;
    }
}
 
Example 30
Source Project: marathonv5   Source File: SplitDockingContainer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void remove(Node container) {
    container.getProperties().remove(DockingDesktop.DOCKING_CONTAINER);
    getItems().remove(container);
    if (getItems().size() == 0) {
        ((IDockingContainer) getProperties().get(DockingDesktop.DOCKING_CONTAINER)).remove(this);
    }
}