public void start(final Stage primaryStage) { primaryStage.setTitle("Popup Example"); final Popup popup = new Popup(); popup.setX(300); popup.setY(200); popup.getContent().addAll(new Circle(25, 25, 50, Color.AQUAMARINE)); Button show = new Button("Show"); show.setOnAction( new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { popup.show(primaryStage); } }); Button hide = new Button("Hide"); hide.setOnAction( new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { popup.hide(); } }); HBox layout = new HBox(10); layout.setStyle("-fx-background-color: cornsilk; -fx-padding: 10;"); layout.getChildren().addAll(show, hide); primaryStage.setScene(new Scene(layout)); primaryStage.show(); }
private void populatePopup(List<String> searchResult) { listView = new ListView<>(); listView.setOnMouseClicked( new EventHandler<MouseEvent>() { public void handle(MouseEvent mouseEvent) { ObservableList<String> itemSelecionado = listView.getSelectionModel().getSelectedItems(); String selected = listView.getSelectionModel().getSelectedItem(); setText(selected); popup.hide(); positionCaret(selected.length()); } }); listView.setOnKeyPressed( new EventHandler<KeyEvent>() { public void handle(KeyEvent keyEvent) { if (keyEvent.getCode().equals(KeyCode.ENTER)) { String selected = listView.getSelectionModel().getSelectedItem(); if (selected == null || selected.isEmpty()) { return; } setText(selected); popup.hide(); positionCaret(selected.length()); } else if (keyEvent.getCode().equals(KeyCode.ESCAPE)) { popup.hide(); setText(""); } } }); listView.getItems().clear(); int count = searchResult.size(); for (int i = 0; i < count; i++) { final String result = searchResult.get(i); listView.getItems().add(result); } if ((count * 26) + 10 < maxHeight) { listView.setMaxHeight((count * 26) + 10); } else { listView.setMaxHeight(maxHeight); } listView.setMaxWidth(getWidth()); popup.getContent().clear(); popup.getContent().add(listView); }
public Progress(Stage owner) { this.owner = owner; Pane content = new Pane(); content.setPrefWidth(200); content.setPrefHeight(200); indicator = new ProgressIndicator(-1.0); indicator.setStyle(" -fx-progress-color: white;"); indicator.setTranslateX(60); indicator.setTranslateY(60); indicator.setPrefWidth(80); indicator.setPrefHeight(80); Rectangle back = new Rectangle(100, 100); back.setFill(Color.color(0, 0, 0, 0.5)); back.setArcHeight(10); back.setArcWidth(10); back.setTranslateX(50); back.setTranslateY(50); content.getChildren().addAll(back, indicator); popup = new Popup(); popup.getContent().addAll(content); popup.setAutoFix(true); }
/** * A Popup containing Listview is trigged from this function This function automatically resize * it's height and width according to the width of textbox and item's cell height */ public void showPopup(String newValue) { ListView<String> listView = new ListView<>(); listView.setPrefWidth(textField.getWidth()); listView.getSelectionModel().clearSelection(); listView.getFocusModel().focus(-1); listView.setItems(searchItems(newValue)); // Set ListView height if (listView.getItems().size() > getDefaultLimitCount()) { listView.setPrefHeight(getDefaultLimitCount() * getDefaultPrefHeight()); } else { listView.setPrefHeight(listView.getItems().size() * getDefaultPrefHeight()); } listView.setOnMouseReleased( event -> { textField.setText(listView.getSelectionModel().getSelectedItem()); textField.requestFocus(); textField.requestLayout(); textField.end(); popup.hide(); onSelectAction(listView.getSelectionModel().getSelectedItem()); }); listView.setOnKeyReleased( event -> { switch (event.getCode()) { case ENTER: textField.setText(listView.getSelectionModel().getSelectedItem()); textField.requestFocus(); textField.requestLayout(); textField.end(); popup.hide(); onSelectAction(listView.getSelectionModel().getSelectedItem()); break; default: break; } }); // This cell factory helps to know which cell has been selected so that // when ever any cell is selected the textbox rawText must be changed listView.setCellFactory( view -> { // A simple ListCell containing only Label final ListCell<String> cell = new ListCell<String>() { public void updateItem(String item, boolean empty) { super.updateItem(item, empty); setText(item); } }; return cell; }); popup.getContent().clear(); popup.getContent().add(listView); // SHOWING THE POPUP JUST BELOW TEXTBOX popup.show( getWindow(), getWindow().getX() + textField.localToScene(0, 0).getX() + textField.getScene().getX(), getWindow().getY() + textField.localToScene(0, 0).getY() + textField.getScene().getY() + getDefaultPrefHeight()); }
public GridPane build() { area = getNewGrid(); for (int i = 0; i < eaTabs.size(); i++) { EATab eaTab = eaTabs.get(i); /*Label label = new Label(eaTab.getTabText() + " Gen: 0"); eaTab.fitnessGrapher.genHolder.addListener((val) -> { label.setText(eaTab.getTabText() + " Gen: " + (Integer)val); });*/ final Label label = new Label(eaTab.getTabText() + " Fit: --"); eaTab.fitnessGrapher.fitHolder.addListener( (val) -> { label.setText( eaTab.getTabText() + " Fit: " + (Math.round(((Double) val) * 100.0) / 100.0)); }); final Popup popup = new Popup(); final Label popupMessage = new Label(label.getText()); popupMessage.getStylesheets().add("./ui/css/style.css"); popupMessage.getStyleClass().add("popup"); label.setOnMouseEntered( event -> { popup.setAnchorX(event.getScreenX() + 20); popup.setAnchorY(event.getScreenY()); popup.setAutoFix(true); popup.setHideOnEscape(true); popup.getContent().clear(); popup.getContent().add(popupMessage); popup.show(GUI.stage); }); label.setOnMouseExited( event -> { popup.hide(); }); Line line = new Line(); line.setEndX(100); line.setStroke(Paint.valueOf("B4B4B4")); GridPane.setColumnSpan(line, 2); GridPane.setRowSpan(line, 1); GridPane.setHalignment(line, HPos.CENTER); GridPane.setValignment(line, VPos.CENTER); area.add(line, 0, i * 2 + 1); TetheredProgressBar progress = new TetheredProgressBar(eaTab.progressBar); StackPane sp = new StackPane(); sp.getChildren().add(label); StackPane sp2 = new StackPane(); sp2.getChildren().add(progress); VBox vbox = new VBox(); vbox.getChildren().addAll(sp, sp2); HBox hbox = new HBox(); TetheredButton button = new TetheredButton(eaTab.startButton); MenuButton mb = new MenuButton(); mb.setText("..."); MenuItem save = new MenuItem("Save"); save.setOnAction( (event) -> { System.out.println("SAVE"); fxController.saveEvolution(eaTab); }); MenuItem close = new MenuItem("Close"); close.setOnAction( (event) -> { fxController.closeTab(eaTab); }); mb.getItems().addAll(save, close, new MenuItem("Send")); hbox.getChildren().addAll(button, mb); hbox.setSpacing(5); area.add(vbox, 0, i * 2); area.add(hbox, 1, i * 2); // button = null; } return area; }
public ColorPickerPopover() { getStyleClass().add("color-picker-popover"); popup.setAutoHide(true); // add this to popup popup.getContent().add(this); // load stylesheet getStylesheets().add(ColorPicker.class.getResource("ColorPicker.css").toString()); // create popover path for main shape final Path p = new Path(); p.getElements() .addAll( new MoveTo(PICKER_PADDING, PICKER_PADDING + ARROW_SIZE + RADIUS), new ArcTo( RADIUS, RADIUS, 90, PICKER_PADDING + RADIUS, PICKER_PADDING + ARROW_SIZE, false, true), new LineTo(PICKER_PADDING + ARROW_X - (ARROW_SIZE * 0.8), PICKER_PADDING + ARROW_SIZE), new LineTo(PICKER_PADDING + ARROW_X, PICKER_PADDING), new LineTo(PICKER_PADDING + ARROW_X + (ARROW_SIZE * 0.8), PICKER_PADDING + ARROW_SIZE), new LineTo(PICKER_PADDING + PICKER_WIDTH - RADIUS, PICKER_PADDING + ARROW_SIZE), new ArcTo( RADIUS, RADIUS, 90, PICKER_PADDING + PICKER_WIDTH, PICKER_PADDING + ARROW_SIZE + RADIUS, false, true), new LineTo( PICKER_PADDING + PICKER_WIDTH, PICKER_PADDING + ARROW_SIZE + PICKER_HEIGHT - RADIUS), new ArcTo( RADIUS, RADIUS, 90, PICKER_PADDING + PICKER_WIDTH - RADIUS, PICKER_PADDING + ARROW_SIZE + PICKER_HEIGHT, false, true), new LineTo(PICKER_PADDING + RADIUS, PICKER_PADDING + ARROW_SIZE + PICKER_HEIGHT), new ArcTo( RADIUS, RADIUS, 90, PICKER_PADDING, PICKER_PADDING + ARROW_SIZE + PICKER_HEIGHT - RADIUS, false, true), new ClosePath()); p.setFill( new LinearGradient( 0, 0, 0, 1, true, CycleMethod.NO_CYCLE, new Stop(0, Color.web("#313131")), new Stop(0.5, Color.web("#5f5f5f")), new Stop(1, Color.web("#313131")))); p.setStroke(null); p.setEffect(new DropShadow(15, 0, 1, Color.gray(0, 0.6))); p.setCache(true); // create rectangle to capture mouse events to hide Rectangle windowClickRect = RectangleBuilder.create() .width(PICKER_PADDING + PICKER_WIDTH + PICKER_PADDING) .height(PICKER_PADDING + PICKER_HEIGHT + PICKER_PADDING) .fill(Color.TRANSPARENT) .onMouseClicked( new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { System.out.println("x= " + event.getX()); System.out.println( "p.contains(event.getX(), event.getY()) = " + p.contains(event.getX(), event.getY())); if (!p.contains(event.getX(), event.getY())) { hide(); } } }) .build(); final Circle colorRectIndicator = CircleBuilder.create() .centerX(60) .centerY(60) .radius(5) .stroke(Color.WHITE) .fill(null) .effect(new DropShadow(2, 0, 1, Color.BLACK)) .build(); colorRectIndicator .centerXProperty() .bind( new DoubleBinding() { { bind(sat); } @Override protected double computeValue() { return (PICKER_PADDING + 10) + (RECT_SIZE * (sat.get() / 100)); } }); colorRectIndicator .centerYProperty() .bind( new DoubleBinding() { { bind(bright); } @Override protected double computeValue() { return (PICKER_PADDING + ARROW_SIZE + 10) + (RECT_SIZE * (1 - (bright.get() / 100))); } }); final Rectangle colorRect = RectangleBuilder.create() .x(PICKER_PADDING + 10) .y(PICKER_PADDING + ARROW_SIZE + 10) .width(RECT_SIZE) .height(RECT_SIZE) .build(); colorRect .fillProperty() .bind( new ObjectBinding<Paint>() { { bind(color); } @Override protected Paint computeValue() { return Color.hsb(hue.getValue(), 1, 1); } }); Rectangle colorRectOverlayOne = RectangleBuilder.create() .x(PICKER_PADDING + 10) .y(PICKER_PADDING + ARROW_SIZE + 10) .width(RECT_SIZE) .height(RECT_SIZE) .fill( new LinearGradient( 0, 0, 1, 0, true, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(255, 255, 255, 1)), new Stop(1, Color.rgb(255, 255, 255, 0)))) .build(); EventHandler<MouseEvent> rectMouseHandler = new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { final double x = event.getX() - colorRect.getX(); final double y = event.getY() - colorRect.getY(); sat.set(clamp(x / RECT_SIZE) * 100); bright.set(100 - (clamp(y / RECT_SIZE) * 100)); } }; Rectangle colorRectOverlayTwo = RectangleBuilder.create() .x(PICKER_PADDING + 10) .y(PICKER_PADDING + ARROW_SIZE + 10) .width(RECT_SIZE) .height(RECT_SIZE) .fill( new LinearGradient( 0, 0, 0, 1, true, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(0, 0, 0, 0)), new Stop(1, Color.rgb(0, 0, 0, 1)))) .onMouseDragged(rectMouseHandler) .onMouseClicked(rectMouseHandler) .build(); final Rectangle colorBar = RectangleBuilder.create() .x(PICKER_PADDING + PICKER_WIDTH - 30) .y(PICKER_PADDING + ARROW_SIZE + 10) .width(20) .height(RECT_SIZE) .fill(createHueGradient()) .build(); final Rectangle colorBarIndicator = RectangleBuilder.create() .x(PICKER_PADDING + PICKER_WIDTH - 32) .y(PICKER_PADDING + ARROW_SIZE + 15) .width(24) .height(10) .arcWidth(4) .arcHeight(4) .stroke(Color.WHITE) .fill(null) .effect(new DropShadow(2, 0, 1, Color.BLACK)) .build(); colorBarIndicator .yProperty() .bind( new DoubleBinding() { { bind(hue); } @Override protected double computeValue() { return (PICKER_PADDING + ARROW_SIZE + 5) + (RECT_SIZE * (hue.get() / 360)); } }); EventHandler<MouseEvent> barMouseHandler = new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { final double y = event.getY() - colorBar.getY(); hue.set(clamp(y / RECT_SIZE) * 360); } }; colorBar.setOnMouseDragged(barMouseHandler); colorBar.setOnMouseClicked(barMouseHandler); Label brightnessLabel = new Label("Brightness:"); brightnessLabel.setMinWidth(Control.USE_PREF_SIZE); GridPane.setConstraints(brightnessLabel, 0, 0); Slider brightnessSlider = SliderBuilder.create().min(0).max(100).id("BrightnessSlider").build(); brightnessSlider.valueProperty().bindBidirectional(bright); GridPane.setConstraints(brightnessSlider, 1, 0); IntegerField brightnessField = new IntegerField(); brightnessField.valueProperty().bindBidirectional(bright); brightnessField.setPrefColumnCount(7); GridPane.setConstraints(brightnessField, 2, 0); Label saturationLabel = new Label("Saturation:"); saturationLabel.setMinWidth(Control.USE_PREF_SIZE); GridPane.setConstraints(saturationLabel, 0, 1); Slider saturationSlider = SliderBuilder.create().min(0).max(100).id("SaturationSlider").build(); saturationSlider.valueProperty().bindBidirectional(sat); GridPane.setConstraints(saturationSlider, 1, 1); saturationSlider .styleProperty() .bind( new StringBinding() { { bind(color); } @Override protected String computeValue() { return "picker-color: hsb(" + hue.get() + ",100%,100%);"; } }); IntegerField saturationField = new IntegerField(); saturationField.valueProperty().bindBidirectional(sat); saturationField.setPrefColumnCount(7); GridPane.setConstraints(saturationField, 2, 1); Label webLabel = new Label("Web:"); webLabel.setMinWidth(Control.USE_PREF_SIZE); GridPane.setConstraints(webLabel, 0, 2); WebColorField webField = new WebColorField(); webField.valueProperty().bindBidirectional(color); GridPane.setConstraints(webField, 1, 2, 2, 1); GridPane controls = new GridPane(); controls.setVgap(5); controls.setHgap(5); controls .getChildren() .addAll( brightnessLabel, brightnessSlider, brightnessField, saturationLabel, saturationSlider, saturationField, webLabel, webField); controls.setManaged(false); controls.resizeRelocate( PICKER_PADDING + 10, PICKER_PADDING + ARROW_SIZE + 10 + 170 + 10, PICKER_WIDTH - 20, controls.getPrefHeight()); getChildren() .addAll( windowClickRect, p, colorRect, colorRectOverlayOne, colorRectOverlayTwo, colorBar, colorRectIndicator, colorBarIndicator, controls); }