Java Code Examples for javafx.stage.Popup#show()

The following examples show how to use javafx.stage.Popup#show() . 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: FxmlControl.java    From MyBox with Apache License 2.0 6 votes vote down vote up
public static void popText(String text, String color, String size,
        Stage stage) {
    try {
        Popup popup = new Popup();
        popup.setAutoHide(true);
        popup.setAutoFix(true);
        Label popupLabel = new Label(text);
        popupLabel.setStyle("-fx-background-color:black;"
                + " -fx-text-fill: " + color + ";"
                + " -fx-font-size: " + size + ";"
                + " -fx-padding: 10px;"
                + " -fx-background-radius: 6;");
        popup.getContent().add(popupLabel);

        popup.show(stage);

    } catch (Exception e) {

    }
}
 
Example 2
Source File: ListViewHelperMainController.java    From examples-javafx-repos1 with Apache License 2.0 6 votes vote down vote up
@FXML
public void showEmployeesHelper(ActionEvent evt) {
	
	Button btn = (Button)evt.getSource();
	
	Point2D point = btn.localToScreen(0.0d + btn.getWidth(), 0.0d - btn.getHeight());
	
	try {
		
		Popup employeesHelper = new ListViewHelperEmployeesPopup(tfEmployee, point);
		
		employeesHelper.show(btn.getScene().getWindow());
	
	} catch(Exception exc) {
		exc.printStackTrace();
		Alert alert = new Alert(AlertType.ERROR, "Error creating employees popup; exiting");
		alert.showAndWait();
		btn.getScene().getWindow().hide();  // close and implicit exit
	}
}
 
Example 3
Source File: CardPlayedToken.java    From metastone with GNU General Public License v2.0 6 votes vote down vote up
public CardPlayedToken(GameBoardView boardView, Card card) {
	Window parent = boardView.getScene().getWindow();
	this.cardToken = new CardTooltip();

	popup = new Popup();
	popup.getContent().setAll(cardToken);
	popup.setX(parent.getX() + 40);
	popup.show(parent);
	popup.setY(parent.getY() + parent.getHeight() * 0.5 - cardToken.getHeight() * 0.5);

	cardToken.setCard(card);

	NotificationProxy.sendNotification(GameNotification.ANIMATION_STARTED);
	FadeTransition animation = new FadeTransition(Duration.seconds(1.2), cardToken);
	animation.setDelay(Duration.seconds(0.6f));
	animation.setOnFinished(this::onComplete);
	animation.setFromValue(1);
	animation.setToValue(0);
	animation.play();
}
 
Example 4
Source File: CardRevealedToken.java    From metastone with GNU General Public License v2.0 6 votes vote down vote up
public CardRevealedToken(GameBoardView boardView, Card card, double delay) {
	Window parent = boardView.getScene().getWindow();
	this.cardToken = new CardTooltip();

	popup = new Popup();
	popup.getContent().setAll(cardToken);
	popup.setX(parent.getX() + 40);
	popup.show(parent);
	popup.setY(parent.getY() + parent.getHeight() * 0.5 - cardToken.getHeight() * 0.5);

	cardToken.setCard(card);
	NotificationProxy.sendNotification(GameNotification.ANIMATION_STARTED);
	FadeTransition animation = new FadeTransition(Duration.seconds(delay), cardToken);
	animation.setOnFinished(this::secondTransition);
	animation.setFromValue(0);
	animation.setToValue(0);
	animation.play();
}
 
Example 5
Source File: PopupSelectbox.java    From logbook-kai with MIT License 6 votes vote down vote up
public void show(Node anchorNode) {
    PopupSelectboxContainer<T> container = new PopupSelectboxContainer<>();
    container.setItems(this.items.get());
    container.setCellFactory(this.cellFactory.get());
    container.setSelectedItem(this.selectedItem);
    container.getStylesheets().addAll(this.styleSheets);
    container.headerContents().addAll(this.headerContents);
    container.init();

    Popup stage = new Popup();
    stage.getContent().addAll(container);
    stage.setAutoHide(true);
    stage.setAnchorLocation(PopupWindow.AnchorLocation.CONTENT_TOP_LEFT);

    Bounds screen = anchorNode.localToScreen(anchorNode.getLayoutBounds());
    stage.show(anchorNode.getScene().getWindow(), screen.getMinX(), screen.getMaxY());
}
 
Example 6
Source File: SimplePopups.java    From pmd-designer with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Show a transient popup with a message, to let the user know an action
 * was performed.
 *
 * @param owner Node next to which the popup will be shown
 * @return
 */
public static EventStream<?> showActionFeedback(@NonNull Node owner,
                                                @Nullable Node graphic,
                                                @NonNull String message,
                                                double offsetX,
                                                boolean stick,
                                                String... cssClasses) {

    Popup popup = new Popup();
    Label label = new Label(message, graphic);
    StackPane pane = new StackPane();

    DesignerUtil.addCustomStyleSheets(pane, "designer");
    pane.getStyleClass().addAll("action-feedback");
    pane.getStyleClass().addAll(cssClasses);

    pane.getChildren().addAll(label);
    popup.getContent().addAll(pane);

    Animation fadeTransition = stick ? fadeInAnimation(pane) : bounceFadeAnimation(pane);
    EventSource<?> closeTick = new EventSource<>();
    if (stick) {
        pane.setOnMouseClicked(evt -> {
            popup.hide();
            closeTick.push(null);
        });
    } else {
        fadeTransition.setOnFinished(e -> {
            popup.hide();
            closeTick.push(null);
        });
    }

    popup.setOnShowing(e -> fadeTransition.play());

    Bounds screenBounds = owner.localToScreen(owner.getBoundsInLocal());
    popup.show(owner, screenBounds.getMaxX() + offsetX, screenBounds.getMinY());
    return closeTick;
}
 
Example 7
Source File: GenerateCodeDialog.java    From tcMenu with Apache License 2.0 5 votes vote down vote up
private void selectPlugin(List<CodePluginItem> pluginItems, String changeWhat, Consumer<CodePluginItem> eventHandler) {

        Popup popup = new Popup();
        List<UICodePluginItem> listOfComponents = pluginItems.stream()
                .map(display -> {
                    var it = new UICodePluginItem(manager, display, SELECT, item -> {
                        popup.hide();
                        eventHandler.accept(item);
                    });
                    it.setId("sel-" + display.getId());

                    return it;
                })
                .collect(Collectors.toList());

        VBox vbox = new VBox(5);
        addTitleLabel(vbox, "Select the " + changeWhat + " to use:");
        vbox.getChildren().addAll(listOfComponents);
        vbox.setPrefSize(700, 600);

        BorderPane pane = new BorderPane();
        pane.setCenter(vbox);
        vbox.getStyleClass().add("popupWindow");

        popup.getContent().add(pane);
        popup.setAutoHide(true);
        popup.setOnAutoHide(event -> popup.hide());
        popup.setHideOnEscape(true);
        popup.show(dialogStage);
    }
 
Example 8
Source File: JoustToken.java    From metastone with GNU General Public License v2.0 5 votes vote down vote up
public JoustToken(GameBoardView boardView, Card card, boolean up, boolean won) {
	Window parent = boardView.getScene().getWindow();
	this.cardToken = new CardTooltip();

	popup = new Popup();
	popup.getContent().setAll(cardToken);
	popup.setX(parent.getX() + 600);
	popup.show(parent);
	int offsetY = up ? -200 : 100;
	popup.setY(parent.getY() + parent.getHeight() * 0.5 - cardToken.getHeight() * 0.5 + offsetY);

	cardToken.setCard(card);

	NotificationProxy.sendNotification(GameNotification.ANIMATION_STARTED);
	FadeTransition animation = new FadeTransition(Duration.seconds(1.0), cardToken);
	animation.setDelay(Duration.seconds(1f));
	animation.setOnFinished(this::onComplete);
	animation.setFromValue(1);
	animation.setToValue(0);
	animation.play();
	
	if (won) {
		ScaleTransition scaleAnimation = new ScaleTransition(Duration.seconds(0.5f), cardToken);
		scaleAnimation.setByX(0.1);
		scaleAnimation.setByY(0.1);
		scaleAnimation.setCycleCount(2);
		scaleAnimation.setAutoReverse(true);
		scaleAnimation.play();	
	}
}
 
Example 9
Source File: PopOver.java    From logbook-kai with MIT License 5 votes vote down vote up
/**
 * マウスがこのアンカーノードに入るときに呼び出される関数を定義します。
 *
 * @param event {@link MouseEvent}
 */
protected void setOnMouseEntered(MouseEvent event) {
    Node anchorNode = (Node) event.getSource();
    Popup popup = this.initPopup(anchorNode);
    Bounds screen = anchorNode.localToScreen(anchorNode.getLayoutBounds());
    popup.setAnchorLocation(PopupWindow.AnchorLocation.CONTENT_TOP_LEFT);
    popup.show(anchorNode.getScene().getWindow(), screen.getMinX(), screen.getMaxY());
    this.setLocation(popup, anchorNode, event);
}
 
Example 10
Source File: SearchableTreeView.java    From pmd-designer with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Textfield for the search query.
 */
private void popSearchField() {
    TextField textField = new TextField();
    textField.setPrefWidth(150);
    textField.setPromptText("Search tree");
    ControlUtil.makeTextFieldShowPromptEvenIfFocused(textField);

    Label label = new Label();
    label.getStyleClass().addAll("hint-label");
    label.setTooltip(new Tooltip("Go to next result with F3"));

    StackPane pane = new StackPane();
    pane.getStyleClass().addAll("search-popup");
    pane.getStylesheets().addAll(DesignerUtil.getCss("designer").toString());

    StackPane.setAlignment(textField, Pos.TOP_RIGHT);
    StackPane.setAlignment(label, Pos.BOTTOM_RIGHT);


    pane.getChildren().addAll(textField, label);

    Val<String> query = Val.wrap(textField.textProperty())
                           .filter(StringUtils::isNotBlank).map(String::trim)
                           .filter(it -> it.length() >= MIN_QUERY_LENGTH);

    Var<Integer> numResults = Var.newSimpleVar(0);

    Subscription subscription = bindSearchQuery(query.conditionOnShowing(pane), numResults, textField);

    label.textProperty().bind(
        numResults.map(n -> n == 0 ? "no match" : n == 1 ? "1 match" : n + " matches")
    );

    label.visibleProperty().bind(query.map(Objects::nonNull));

    Popup popup = new Popup();
    popup.getContent().addAll(pane);
    popup.setAutoHide(true);
    popup.setHideOnEscape(true);

    Bounds bounds = localToScreen(getBoundsInLocal());
    popup.show(this, bounds.getMaxX() - textField.getPrefWidth() - 1, bounds.getMinY());
    popup.setOnHidden(e -> {
        openSearchField = null;
        subscription.unsubscribe();
    }); // release resources

    // Hide popup when ENTER or ESCAPE is pressed
    EventStreams.eventsOf(popup, KeyEvent.KEY_RELEASED)
                .filter(it -> it.getCode() == KeyCode.ENTER || it.getCode() == KeyCode.ESCAPE)
                .subscribeForOne(e -> {
                    popup.hide();
                    e.consume();
                });

    textField.requestFocus();
    openSearchField = textField;
}
 
Example 11
Source File: ImagesBrowserController.java    From MyBox with Apache License 2.0 4 votes vote down vote up
private void makeImagePopup(VBox imageBox, ImageInformation imageInfo,
        ImageView iView) {
    try {
        File file = imageInfo.getImageFileInformation().getFile();
        final Image iImage = imageInfo.getImage();
        imagePop = new Popup();
        imagePop.setWidth(popSize + 40);
        imagePop.setHeight(popSize + 40);
        imagePop.setAutoHide(true);

        VBox vbox = new VBox();
        VBox.setVgrow(vbox, Priority.ALWAYS);
        HBox.setHgrow(vbox, Priority.ALWAYS);
        vbox.setMaxWidth(Double.MAX_VALUE);
        vbox.setMaxHeight(Double.MAX_VALUE);
        vbox.setStyle("-fx-background-color: white;");
        imagePop.getContent().add(vbox);

        popView = new ImageView();
        popView.setImage(iImage);
        if (iImage.getWidth() > iImage.getHeight()) {
            popView.setFitWidth(popSize);
        } else {
            popView.setFitHeight(popSize);
        }
        popView.setPreserveRatio(true);
        vbox.getChildren().add(popView);

        popText = new Text();
        popText.setStyle("-fx-font-size: 1.0em;");

        vbox.getChildren().add(popText);
        vbox.setPadding(new Insets(15, 15, 15, 15));

        String info = imageInfo.getFileName() + "\n"
                + AppVariables.message("Format") + ":" + imageInfo.getImageFormat() + "  "
                + AppVariables.message("ModifyTime") + ":" + DateTools.datetimeToString(file.lastModified()) + "\n"
                + AppVariables.message("Size") + ":" + FileTools.showFileSize(file.length()) + "  "
                + AppVariables.message("Pixels") + ":" + imageInfo.getWidth() + "x" + imageInfo.getHeight() + "\n"
                + AppVariables.message("LoadedSize") + ":"
                + (int) iView.getImage().getWidth() + "x" + (int) iView.getImage().getHeight() + "  "
                + AppVariables.message("DisplayedSize") + ":"
                + (int) iView.getFitWidth() + "x" + (int) iView.getFitHeight();
        popText.setText(info);
        popText.setWrappingWidth(popSize);
        Bounds bounds = imageBox.localToScreen(imageBox.getBoundsInLocal());
        imagePop.show(imageBox, bounds.getMinX() + bounds.getWidth() / 2, bounds.getMinY());

    } catch (Exception e) {
        logger.debug(e.toString());
    }
}
 
Example 12
Source File: PersonTypeCellFactory.java    From examples-javafx-repos1 with Apache License 2.0 4 votes vote down vote up
@Override
 public TableCell<Person, String> call(TableColumn<Person, String> param) {

     return new ComboBoxTableCell<Person, String>(new DefaultStringConverter()) {      
     	
     	{
         	ContextMenu cm = new ContextMenu();
         	MenuItem deletePersonsMenuItem = new MenuItem("Delete");
         	deletePersonsMenuItem.setOnAction( PersonTypeCellFactory.this.deletePersonsHandler );
         	cm.getItems().add(deletePersonsMenuItem);
         	this.setContextMenu(cm);    
         	
         	this.getItems().addAll( "Friend", "Co-worker", "Other" );
         	
         	this.setEditable(true);
     	}
     	
         @Override
         public void updateItem(String arg0, boolean empty) {
         	
             super.updateItem(arg0, empty);
             
             if( !empty ) {
                 this.setText( arg0 );
             } else {
                 this.setText( null );  // clear from recycled obj
             }
         }

@SuppressWarnings("unchecked")
@Override
public void commitEdit(String newValue) {
	super.commitEdit(newValue);
	TableRow<Person> row = this.getTableRow();
	Person p = row.getItem();
	
	String msg = p.validate();
	if( logger.isLoggable(Level.FINE) ) {
		logger.fine("[COMMIT EDIT] validate=" + msg);
	}
		
	if( msg == null || msg.isEmpty() ) {
		if( logger.isLoggable(Level.FINE) ) {
			logger.fine("[COMMIT EDIT] validation passed");
		}
		Task<Void> task = new Task<Void>() {
			@Override
			protected Void call() {
				dao.updatePerson(p);  // updates AR too
				return null;
			}
		};
		new Thread(task).start();
	} else {
		
		System.out.println("layoutBounds=" + this.getLayoutBounds());
		System.out.println("boundsInLocal=" + this.getBoundsInLocal());
		System.out.println("boundsInParent=" + this.getBoundsInParent());
		System.out.println("boundsInParent (Scene)=" + this.localToScene(this.getBoundsInParent()));
		System.out.println("boundsInParent (Screen)=" + this.localToScreen(this.getBoundsInParent()));

		System.out.println("row layoutBounds=" + row.getLayoutBounds());
		System.out.println("row boundsInLocal=" + row.getBoundsInLocal());
		System.out.println("row boundsInParent=" + row.getBoundsInParent());
		System.out.println("row boundsInParent (Scene)=" + row.localToScene(this.getBoundsInParent()));
		System.out.println("row boundsInParent (Screen)=" + row.localToScreen(this.getBoundsInParent()));

		VBox vbox = new VBox();
		vbox.setPadding(new Insets(10.0d));
		vbox.setStyle("-fx-background-color: white; -fx-border-color: red");
		vbox.getChildren().add( new Label(msg));
		//vbox.setEffect(new DropShadow());
		
		Popup popup = new Popup();
		popup.getContent().add( vbox );
		popup.setAutoHide(true);
		popup.setOnShown((evt) -> {
			
			System.out.println("vbox layoutBounds=" + vbox.getLayoutBounds());
			System.out.println("vbox boundsInLocal=" + vbox.getBoundsInLocal());
			System.out.println("vbox boundsInParent=" + vbox.getBoundsInParent());
			System.out.println("vbox boundsInParent (Scene)=" + vbox.localToScene(this.getBoundsInParent()));
			System.out.println("vbox boundsInParent (Screen)=" + vbox.localToScreen(this.getBoundsInParent()));

		});
		popup.show( row, 
				row.localToScreen(row.getBoundsInParent()).getMinX(), 
				row.localToScreen(row.getBoundsInParent()).getMaxY());					
	}
}
     };
 }
 
Example 13
Source File: PersonsCellFactory.java    From examples-javafx-repos1 with Apache License 2.0 4 votes vote down vote up
@Override
 public TableCell<Person, String> call(TableColumn<Person, String> param) {

     return new TextFieldTableCell<Person, String>(new DefaultStringConverter()) {      
     	
     	{
         	ContextMenu cm = new ContextMenu();
         	MenuItem deletePersonsMenuItem = new MenuItem("Delete");
         	deletePersonsMenuItem.setOnAction( PersonsCellFactory.this.deletePersonsHandler );
         	cm.getItems().add(deletePersonsMenuItem);
         	this.setContextMenu(cm);      
     	}
     	
         @Override
         public void updateItem(String arg0, boolean empty) {
         	
             super.updateItem(arg0, empty);
             
             if( !empty ) {
                 this.setText( arg0 );
             } else {
                 this.setText( null );  // clear from recycled obj
             }
         }

@SuppressWarnings("unchecked")
@Override
public void commitEdit(String newValue) {
	super.commitEdit(newValue);
	TableRow<Person> row = this.getTableRow();
	Person p = row.getItem();
	
	String msg = p.validate();
	if( logger.isLoggable(Level.FINE) ) {
		logger.fine("[COMMIT EDIT] validate=" + msg);
	}
		
	if( msg == null || msg.isEmpty() ) {
		if( logger.isLoggable(Level.FINE) ) {
			logger.fine("[COMMIT EDIT] validation passed");
		}
		Task<Void> task = new Task<Void>() {
			@Override
			protected Void call() {
				dao.updatePerson(p);  // updates AR too
				return null;
			}
		};
		new Thread(task).start();
	} else {
		
		System.out.println("layoutBounds=" + this.getLayoutBounds());
		System.out.println("boundsInLocal=" + this.getBoundsInLocal());
		System.out.println("boundsInParent=" + this.getBoundsInParent());
		System.out.println("boundsInParent (Scene)=" + this.localToScene(this.getBoundsInParent()));
		System.out.println("boundsInParent (Screen)=" + this.localToScreen(this.getBoundsInParent()));

		System.out.println("row layoutBounds=" + row.getLayoutBounds());
		System.out.println("row boundsInLocal=" + row.getBoundsInLocal());
		System.out.println("row boundsInParent=" + row.getBoundsInParent());
		System.out.println("row boundsInParent (Scene)=" + row.localToScene(this.getBoundsInParent()));
		System.out.println("row boundsInParent (Screen)=" + row.localToScreen(this.getBoundsInParent()));

		VBox vbox = new VBox();
		vbox.setPadding(new Insets(10.0d));
		vbox.setStyle("-fx-background-color: white; -fx-border-color: red");
		vbox.getChildren().add( new Label(msg));
		//vbox.setEffect(new DropShadow());
		
		Popup popup = new Popup();
		popup.getContent().add( vbox );
		popup.setAutoHide(true);
		popup.setOnShown((evt) -> {
			
			System.out.println("vbox layoutBounds=" + vbox.getLayoutBounds());
			System.out.println("vbox boundsInLocal=" + vbox.getBoundsInLocal());
			System.out.println("vbox boundsInParent=" + vbox.getBoundsInParent());
			System.out.println("vbox boundsInParent (Scene)=" + vbox.localToScene(this.getBoundsInParent()));
			System.out.println("vbox boundsInParent (Screen)=" + vbox.localToScreen(this.getBoundsInParent()));

		});
		popup.show( row, 
				row.localToScreen(row.getBoundsInParent()).getMinX(), 
				row.localToScreen(row.getBoundsInParent()).getMaxY());					
	}
}
     };
 }
 
Example 14
Source File: Notification.java    From Enzo with Apache License 2.0 4 votes vote down vote up
/**
 * Creates and shows a popup with the data from the given Notification object
 * @param NOTIFICATION
 */
private void showPopup(final Notification NOTIFICATION) {
    Label title = new Label(NOTIFICATION.TITLE);
    title.getStyleClass().add("title");

    ImageView icon = new ImageView(NOTIFICATION.IMAGE);
    icon.setFitWidth(ICON_WIDTH);
    icon.setFitHeight(ICON_HEIGHT);

    Label message = new Label(NOTIFICATION.MESSAGE, icon);
    message.getStyleClass().add("message");

    VBox popupLayout = new VBox();
    popupLayout.setSpacing(10);
    popupLayout.setPadding(new Insets(10, 10, 10, 10));
    popupLayout.getChildren().addAll(title, message);

    StackPane popupContent = new StackPane();
    popupContent.setPrefSize(width, height);
    popupContent.getStyleClass().add("notification");
    popupContent.getChildren().addAll(popupLayout);

    final Popup POPUP = new Popup();
    POPUP.setX( getX() );
    POPUP.setY( getY() );
    POPUP.getContent().add(popupContent);

    popups.add(POPUP);

    // Add a timeline for popup fade out
    KeyValue fadeOutBegin = new KeyValue(POPUP.opacityProperty(), 1.0);
    KeyValue fadeOutEnd   = new KeyValue(POPUP.opacityProperty(), 0.0);

    KeyFrame kfBegin = new KeyFrame(Duration.ZERO, fadeOutBegin);
    KeyFrame kfEnd   = new KeyFrame(Duration.millis(500), fadeOutEnd);

    Timeline timeline = new Timeline(kfBegin, kfEnd);
    timeline.setDelay(popupLifetime);
    timeline.setOnFinished(actionEvent -> Platform.runLater(() -> {
        POPUP.hide();
        popups.remove(POPUP);
    }));

    // Move popup to the right during fade out
    //POPUP.opacityProperty().addListener((observableValue, oldOpacity, opacity) -> popup.setX(popup.getX() + (1.0 - opacity.doubleValue()) * popup.getWidth()) );

    if (stage.isShowing()) {
        stage.toFront();
    } else {
        stage.show();
    }

    POPUP.show(stage);
    timeline.play();
}