javafx.scene.Node Java Examples

The following examples show how to use javafx.scene.Node. 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: MainApplicationController.java    From kafka-message-tool with 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 #2
Source File: ModalDialog.java    From marathonv5 with 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 #3
Source File: CellUtils.java    From AsciidocFX with 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 File: DashboardTile.java    From pdfsam with 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 File: ProjectsComboBox.java    From markdown-writer-fx with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@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 #6
Source File: FxDockTabPane.java    From FxDock with 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 File: SendLogbookAction.java    From phoebus with 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
Source File: Properties.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 File: AwesomeService.java    From AsciidocFX with 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 #10
Source File: AppUtils.java    From java-ml-projects with 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 #11
Source File: HoverGesture.java    From gef with 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 #12
Source File: SelectionModel.java    From gef with 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 #13
Source File: PaintingComponentContainer.java    From jmonkeybuilder with 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 #14
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 #15
Source File: StackedFontIcon.java    From ikonli with 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 #16
Source File: CellWrapper.java    From Flowless with 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 #17
Source File: ValidatorBase.java    From JFoenix with 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 #18
Source File: EmbeddedImage.java    From markdown-writer-fx with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 #19
Source File: FocusModel.java    From gef with 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 #20
Source File: AttributeEditorPanel.java    From constellation with 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 #21
Source File: SepiaToneSample.java    From marathonv5 with 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 #22
Source File: LabeledHorizontalBarChart.java    From MyBox with 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 #23
Source File: StackPaneSample.java    From marathonv5 with 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 #24
Source File: DraggableBox.java    From graph-editor with 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 #25
Source File: InfoTextField.java    From bisq with 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 #26
Source File: UITools.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 #27
Source File: SplitDockingContainer.java    From marathonv5 with 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);
    }
}
 
Example #28
Source File: DockStage.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** @param stage Stage for which to dump basic panel hierarchy */
public static void dump(final StringBuilder buf, final Stage stage)
{
    final Node node = getPaneOrSplit(stage);
    buf.append("Stage ").append(stage.getTitle()).append("\n");
    dump(buf, node, 0);
}
 
Example #29
Source File: LineStyleEditorFactory.java    From constellation with Apache License 2.0 5 votes vote down vote up
@Override
protected Node createEditorControls() {
    final GridPane controls = new GridPane();
    controls.setAlignment(Pos.CENTER);
    controls.setHgap(CONTROLS_DEFAULT_HORIZONTAL_SPACING);

    final Label lineStyleLabel = new Label("Line Style:");
    final ObservableList<LineStyle> lineStyles = FXCollections.observableArrayList(LineStyle.values());
    lineStyleComboBox = new ComboBox<>(lineStyles);
    final Callback<ListView<LineStyle>, ListCell<LineStyle>> cellFactory = (final ListView<LineStyle> p) -> new ListCell<LineStyle>() {
        @Override
        protected void updateItem(final LineStyle item, boolean empty) {
            super.updateItem(item, empty);
            if (item != null) {
                setText(item.name());
            }
        }
    };
    lineStyleComboBox.setCellFactory(cellFactory);
    lineStyleComboBox.setButtonCell(cellFactory.call(null));
    lineStyleLabel.setLabelFor(lineStyleComboBox);
    lineStyleComboBox.getSelectionModel().selectedItemProperty().addListener((o, n, v) -> {
        update();
    });

    controls.addRow(0, lineStyleLabel, lineStyleComboBox);
    return controls;
}
 
Example #30
Source File: ActionUtils.java    From markdown-writer-fx with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static Node[] createToolBarButtons(Action... actions) {
	Node[] buttons = new Node[actions.length];
	for (int i = 0; i < actions.length; i++) {
		buttons[i] = (actions[i] != null)
				? createToolBarButton(actions[i])
				: new Separator();
	}
	return buttons;
}