package graphics.api.control.popup; import javafx.event.EventHandler; import javafx.application.Application; import javafx.stage.*; import javafx.scene.*; import javafx.scene.shape.*; import javafx.scene.text.*; import javafx.scene.paint.*; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.beans.property.BooleanProperty; import javafx.beans.value.*; import javafx.event.Event; public class PopupAutofixFails extends Application { private Popup p1; private Button showButton1 = new Button("Show Right"); private Button showButton2 = new Button("Show Left"); private Button showButton3 = new Button("Show Up"); private Button showButton4 = new Button("Show Down"); private Button showButton5 = new Button("Show Out"); private CheckBox checkBox = new CheckBox(); private Rectangle rectangle = new Rectangle(60.0F, 30.0F); private Text textX = new Text(); private Text textY = new Text(); private boolean valuesRetained; private BooleanProperty valuesRetainedV = new BooleanProperty(); Stage stage; private void initBindEvent() { textX.setText("Popup.x: 0"); textY.setText("Popup.y: 0"); rectangle.setFill(Color.GREEN); showButton1.setOnAction(new EventHandler() { public void handle(Event t) { p1.show(stage, Constants.CX14_1, Constants.CY14_1); if (p1.getX() == Constants.CX14_1 && p1.getY() == Constants.CY14_1) { valuesRetained = true; } else { valuesRetained = false; } valuesRetainedV.setValue(valuesRetained); } }); showButton2.setOnAction(new EventHandler() { public void handle(Event t) { p1.show(stage, Constants.CX2, Constants.CY2); if (p1.getX() == Constants.CX2 && p1.getY() == Constants.CY2) { valuesRetained = true; } else { valuesRetained = false; } valuesRetainedV.setValue(valuesRetained); } }); showButton3.setOnAction(new EventHandler() { public void handle(Event t) { p1.show(stage, Constants.CX3, Constants.CY3); if (p1.getX() == Constants.CX3 && p1.getY() == Constants.CY3) { valuesRetained = true; } else { valuesRetained = false; } valuesRetainedV.setValue(valuesRetained); } }); showButton4.setOnAction(new EventHandler() { public void handle(Event t) { p1.show(stage, Constants.CX14_4, Constants.CY14_4); if (p1.getX() == Constants.CX14_4 && p1.getY() == Constants.CY14_4) { valuesRetained = true; } else { valuesRetained = false; } valuesRetainedV.setValue(valuesRetained); } }); showButton5.setOnAction(new EventHandler() { public void handle(Event t) { p1.show(stage, Constants.CX14_5, Constants.CY14_5); if (p1.getX() == Constants.CX14_5 && p1.getY() == Constants.CY14_5) { valuesRetained = true; } else { valuesRetained = false; } } }); checkBox.selectedProperty().addListener(new InvalidationListener() { public void invalidated(ObservableValue ov) { p1.setAutoFix(checkBox.isSelected()); } }); valuesRetainedV.addListener(new InvalidationListener() { public void invalidated(ObservableValue valueModel) { rectangle.setFill((valuesRetainedV.getValue()) ? (Color.GREY) : (Color.GREEN)); } }); p1.xProperty().addListener(new InvalidationListener() { public void invalidated(ObservableValue ov) { textX.setText("Popup.x: " + p1.getX()); textY.setText("Popup.y: " + p1.getY()); } }); p1.yProperty().addListener(new InvalidationListener() { public void invalidated(ObservableValue ov) { textX.setText("Popup.x: " + p1.getX()); textY.setText("Popup.y: " + p1.getY()); } }); } @Override public void start(Stage stage) throws Exception { this.stage = stage; float h = 400; float w = 400; p1 = new Popup(); Scene scene = new Scene(new Group(), w, h); initBindEvent(); checkBox.setText("AutoFix"); checkBox.setSelected(true); p1.setAutoHide(false); StackPane stack = new StackPane(); Ellipse ellipse = new Ellipse(70.0F, 50.0F); ellipse.setFill(Color.BLUE); stack.getChildren().clear(); stack.getChildren().addAll(ellipse, new Text("Popup")); p1.getContent().clear(); p1.getContent().addAll(stack); VBox vbox = new VBox(2.0F); vbox.getChildren().clear(); vbox.getChildren().addAll(checkBox, showButton1, showButton2, showButton3, showButton4, showButton5, textX, textY, rectangle); ((Group) scene.getRoot()).getChildren().clear(); ((Group) scene.getRoot()).getChildren().addAll(vbox); stage.setScene(scene); stage.setVisible(true); } public static void main(String[] args) { PopupAutofixFails.launch(args); } }