private Group createButtonArea(final Scene scene) { // create button area final Group buttonGroup = new Group(); // rounded rect Rectangle buttonArea = RectangleBuilder.create() .arcWidth(15) .arcHeight(20) .fill(new Color(0, 0, 0, .55)) .x(0) .y(0) .width(60) .height(30) .stroke(Color.rgb(255, 255, 255, .70)) .build(); buttonGroup.getChildren().add(buttonArea); // move button group when scene is resized buttonGroup .translateXProperty() .bind(scene.widthProperty().subtract(buttonArea.getWidth() + 6)); buttonGroup .translateYProperty() .bind(scene.heightProperty().subtract(buttonArea.getHeight() + 6)); return buttonGroup; }
@Override public void start(Stage primaryStage) { try { Group root = new Group(); Scene scene = new Scene(root, 400, 400); scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm()); primaryStage.setScene(scene); primaryStage.show(); final Rectangle rectBasicTimeline = new Rectangle(); rectBasicTimeline.setX(0); rectBasicTimeline.setY(0); rectBasicTimeline.widthProperty().bind(scene.widthProperty()); rectBasicTimeline.heightProperty().bind(scene.heightProperty()); rectBasicTimeline.setFill(Color.RED); root.getChildren().add(rectBasicTimeline); final Timeline timeline = new Timeline(); timeline.setCycleCount(Timeline.INDEFINITE); timeline.setAutoReverse(true); final KeyValue kv1 = new KeyValue(rectBasicTimeline.fillProperty(), Color.YELLOW); final KeyValue kv2 = new KeyValue(rectBasicTimeline.fillProperty(), Color.GREEN); final KeyValue kv3 = new KeyValue(rectBasicTimeline.fillProperty(), Color.BLUE); final KeyFrame kf1 = new KeyFrame(Duration.millis(5000), kv1); final KeyFrame kf2 = new KeyFrame(Duration.millis(10000), kv2); final KeyFrame kf3 = new KeyFrame(Duration.millis(15000), kv3); timeline.getKeyFrames().add(kf1); timeline.getKeyFrames().add(kf2); timeline.getKeyFrames().add(kf3); timeline.play(); } catch (Exception e) { e.printStackTrace(); } }
public Controller(View root, Stage stage) { this.root = root; root.openFile.setOnAction( (value) -> { root.pdbObjects.getChildren().clear(); File file = root.fileChooser.showOpenDialog(stage); readPDB(file.getAbsolutePath()); root.fileLabel.setText(file.getName()); }); scene = new Scene(root, 700, 700, true); root.threeDView.widthProperty().bind(scene.widthProperty()); root.threeDView.heightProperty().bind(Bindings.add(-50.0, scene.heightProperty())); scene.setOnMousePressed( (event) -> { mouseStartX = event.getSceneX(); mouseStartY = event.getSceneY(); }); scene.setOnMouseDragged( (event) -> { double deltaX = event.getSceneX() - mouseStartX; double deltaY = event.getSceneY() - mouseStartY; if (event.isShiftDown()) { root.camera.setTranslateZ(root.getTranslateZ() + deltaY * 10); } else { worldRotateY.setAngle(deltaX); worldRotateZ.setAngle(deltaY); } }); }
@Override public void start(Stage primaryStage) throws Exception { top = new Top(this); tWindow = new TeacherWindow(); sWindow = new StudentWindow(); // Parent root = FXMLLoader.load(getClass().getResource("sample.fxml")); primaryStage.setTitle("Jeopardy"); background.setImage(jeopardy); stack.getChildren().add(background); stack.getChildren().add(border); border.setTop(top); Scene scene = new Scene(stack, 800, 800); primaryStage.setScene(scene); background.fitWidthProperty().bind(scene.widthProperty()); background.fitHeightProperty().bind(scene.heightProperty()); primaryStage.show(); top.tButton.setOnAction( e -> { System.out.println("clicked"); displayTeacherWindow(); }); top.sButton.setOnAction( e -> { displayStudentWindow(); }); }
public void init() { this.connectionManager = new ConnectionManager(eventManager, statisticsManager, configurationManager); statisticsManager.loadStats(); // Set up scene scene = getParentWindow().getScene(); // Set up window events getParentWindow() .setOnCloseRequest( new EventHandler<WindowEvent>() { public void handle(WindowEvent t) { exit(); } }); scene .widthProperty() .addListener( new ChangeListener<Number>() { @Override public void changed( ObservableValue<? extends Number> observableValue, Number oldSceneWidth, Number newSceneWidth) { if (!getStage().isMaximized()) { setLastWidth((double) newSceneWidth); } } }); scene .heightProperty() .addListener( new ChangeListener<Number>() { @Override public void changed( ObservableValue<? extends Number> observableValue, Number oldSceneHeight, Number newSceneHeight) { if (!getStage().isMaximized()) { setLastHeight((double) newSceneHeight); } } }); // Clear any test tabs stage.setTitle("mqtt-spy"); controlPanelPaneController.setMainController(this); controlPanelPaneController.setConfigurationMananger(configurationManager); controlPanelPaneController.setApplication(application); controlPanelPaneController.setEventManager(eventManager); controlPanelPaneController.setConnectionManager(connectionManager); controlPanelPaneController.init(); new Thread(new ConnectionStatsUpdater(connectionManager)).start(); }
@Override public void start(Stage primaryStage) throws Exception { Group root = new Group(); Group circles = new Group(); for (int i = 0; i < 30; i++) { Circle circle = new Circle(150, Color.web("white", 0.05)); circle.setStrokeType(StrokeType.OUTSIDE); circle.setStroke(Color.web("white", 0.16)); circle.setStrokeWidth(4); circles.getChildren().add(circle); } root.getChildren().add(circles); Scene scene = new Scene(root, 800, 600, Color.BLACK); Rectangle colors = new Rectangle( scene.getWidth(), scene.getHeight(), new LinearGradient( 0f, 1f, 1f, 0f, true, CycleMethod.NO_CYCLE, new Stop[] { new Stop(0, Color.web("#f8bd55")), new Stop(0.14, Color.web("#c0fe56")), new Stop(0.28, Color.web("#5dfbc1")), new Stop(0.43, Color.web("#64c2f8")), new Stop(0.57, Color.web("#be4af7")), new Stop(0.71, Color.web("#ed5fc2")), new Stop(0.85, Color.web("#ef504c")), new Stop(1, Color.web("#f2660f")), })); colors.widthProperty().bind(scene.widthProperty()); colors.heightProperty().bind(scene.heightProperty()); root.getChildren().add(colors); Timeline timeline = new Timeline(); for (Node circle : circles.getChildren()) { timeline .getKeyFrames() .addAll( new KeyFrame( Duration.ZERO, // set start position at 0 new KeyValue(circle.translateXProperty(), random() * 800), new KeyValue(circle.translateYProperty(), random() * 600)), new KeyFrame( new Duration(40000), // set end position at 40s new KeyValue(circle.translateXProperty(), random() * 800), new KeyValue(circle.translateYProperty(), random() * 600))); } timeline.play(); primaryStage.setScene(scene); primaryStage.show(); }
@Override public void start(Stage primaryStage) { Circle circle = new Circle(); StackPane root = new StackPane(); root.getChildren().add(circle); Scene scene = new Scene(root, 100, 100); circle.centerXProperty().bind(scene.widthProperty().divide(2)); circle.centerYProperty().bind(scene.heightProperty().divide(2)); circle .radiusProperty() .bind(Bindings.min(scene.widthProperty(), scene.heightProperty()).divide(2)); primaryStage.setTitle("Bindings in java fx"); primaryStage.setScene(scene); primaryStage.show(); }
public MovieTile(Movie movie, Scene scene) { super(); this.movie = movie; HBox hbox = new HBox(2); // hbox.setPrefHeight(500); hbox.prefWidthProperty().bind(scene.widthProperty().divide(8)); // hbox.prefHeightProperty().bind(scene.heightProperty().divide(2)); ImageView imgView = new ImageView(); imgView.setImage(new Image("file:" + movie.title.getValue() + ".jpg")); imgView.fitWidthProperty().bind(hbox.widthProperty().divide(2)); // imgView.setPreserveRatio(true); imgView.setSmooth(true); DropShadow ds = new DropShadow(); ds.setRadius(10); ds.setOffsetX(-5); ds.setOffsetY(2); ds.setColor(Color.color(0, 0, 0, 0.3)); imgView.setEffect(ds); VBox vbox = new VBox(2); HBox titleBox = new HBox(2); Text nameField = new Text(); nameField.setTextOrigin(VPos.TOP); nameField.setStroke(Color.BLACK); nameField.textProperty().bind(movie.title); Text dateField = new Text(); dateField.setTextOrigin(VPos.TOP); dateField.setStroke(Color.GRAY); dateField .textProperty() .bind(new SimpleStringProperty(" (").concat(movie.releaseDate).concat(")")); titleBox.getChildren().addAll(nameField, dateField); Text genreField = new Text(); // genreField.prefHeightProperty().bind(hbox.heightProperty().divide(5/1)); genreField.textProperty().bind(movie.genre); TextField comField = new TextField(); // comField.prefHeightProperty().bind(hbox.heightProperty().divide(5/2)); comField.textProperty().bind(movie.comments); vbox.getChildren().addAll(titleBox, genreField, comField); VBox.setVgrow(comField, Priority.ALWAYS); hbox.getChildren().addAll(imgView, vbox); this.getChildren().addAll(hbox); }
public WorkSpaceTabVC(Stage s) { myWorkSpaces = new ArrayList<UserInterfaceVC>(); myTabPane = new TabPane(); myStage = s; myGroup = new Group(); myScene = new Scene(myGroup, SIZE, SIZE); myBorderPane = new BorderPane(); myBorderPane.prefWidthProperty().bind(myScene.widthProperty()); myBorderPane.prefHeightProperty().bind(myScene.heightProperty()); myMenuBar = makeMenuBar(); addAndDisplayTabs(); }
private Node createBackground(Scene scene) { // application area Rectangle applicationArea = RectangleBuilder.create() .arcWidth(20) .arcHeight(20) .fill(Color.rgb(0, 0, 0, .80)) .x(0) .y(0) .strokeWidth(2) .stroke(Color.rgb(255, 255, 255, .70)) .build(); applicationArea.widthProperty().bind(scene.widthProperty()); applicationArea.heightProperty().bind(scene.heightProperty()); return applicationArea; }
@Override public void start(Stage stage) { Canvas canvas = new Canvas(600, 600); GraphicsContext gc = canvas.getGraphicsContext2D(); gc.setStroke(Color.BLACK); canvas.setOnMousePressed( event -> { gc.moveTo(event.getX(), event.getY()); }); canvas.setOnMouseDragged( event -> { gc.lineTo(event.getX(), event.getY()); gc.stroke(); }); Group root = new Group(canvas); Scene scene = new Scene(root, 600, 600); canvas.widthProperty().bind(scene.widthProperty()); canvas.heightProperty().bind(scene.heightProperty()); stage.setScene(scene); stage.show(); }
private Node createCloseButton(Scene scene) { // close button final Group closeApp = new Group(); Circle closeButton = CircleBuilder.create() .centerX(5) .centerY(0) .radius(7) .fill(Color.rgb(255, 255, 255, .80)) .build(); Text closeXmark = new Text(2, 4, "X"); closeApp.translateXProperty().bind(scene.widthProperty().subtract(15)); closeApp.setTranslateY(10); closeApp.getChildren().addAll(closeButton, closeXmark); closeApp.setOnMouseClicked( new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { Platform.exit(); } }); return closeApp; }
@Override public void start(Stage theStage) { this.tStage = theStage; theStage.setTitle("Ball of Duty"); theStage.setHeight(WINDOW_START_HEIGHT); theStage.setWidth(WINDOW_START_WIDTH); theStage.centerOnScreen(); theStage.setResizable(false); theStage.setOnCloseRequest( new EventHandler<WindowEvent>() { public void handle(WindowEvent we) { gameManager.quitGame(); System.exit(0); } }); BorderPane startMenuRoot = new BorderPane(); startMenu = new Scene(startMenuRoot); gameBox = new BorderPane(); Scene gameScene = new Scene(gameBox); BorderPane createAccountRoot = new BorderPane(); BorderPane lohInRoot = new BorderPane(); theStage.setScene(startMenu); gameManager = new GameClient(getRelativeSceneLocation(theStage)); scale = new Scale(); scale.xProperty().bind(gameScene.widthProperty().divide(WINDOW_START_WIDTH)); scale.yProperty().bind(gameScene.heightProperty().divide(WINDOW_START_HEIGHT)); scale.setPivotX(0); scale.setPivotY(0); // gameBox.getTransforms().add(scale); // gameBox.setBackground(null); // TODO scaling theStage .heightProperty() .addListener( e -> { gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage)); // This // only // happens // once // for // some // reason. }); theStage .widthProperty() .addListener( e -> { gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage)); }); theStage .xProperty() .addListener( e -> { gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage)); }); theStage .yProperty() .addListener( e -> { gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage)); }); gameScene .xProperty() .addListener( e -> { gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage)); }); gameScene .yProperty() .addListener( e -> { gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage)); }); Image image = new Image("images/frontpage.png"); BackgroundSize backgroundSize = new BackgroundSize(100, 100, true, true, true, false); // new BackgroundImage(image, repeatX, repeatY, position, size) BackgroundImage backgroundImage = new BackgroundImage( image, BackgroundRepeat.REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER, backgroundSize); // new Background(images...) Background background = new Background(backgroundImage); startMenuRoot.setBackground(background); RadioButton chooseBlaster = new RadioButton("Blaster"); RadioButton chooseRoller = new RadioButton("Roller"); RadioButton chooseHeavy = new RadioButton("Heavy"); final ToggleGroup specializationGroup = new ToggleGroup(); chooseBlaster.setToggleGroup(specializationGroup); chooseRoller.setToggleGroup(specializationGroup); chooseHeavy.setToggleGroup(specializationGroup); chooseBlaster.setSelected(true); HBox specializationBox = new HBox(); specializationBox.setSpacing(9); specializationBox.getChildren().add(chooseBlaster); specializationBox.getChildren().add(chooseRoller); specializationBox.getChildren().add(chooseHeavy); Label lblNickname = new Label("Nickname:"); TextField tfNickname = new TextField(); Button loginStart = new Button("Log in"); Button createStart = new Button("Create Account"); theStage.getIcons().add(new Image("images/ball_red.png")); VBox mainButtonBox = new VBox(); mainButtonBox.setSpacing(5); Button joinBtn = new Button("Join game"); Button viewLB = new Button("Leaderboard"); viewLB.setPrefSize(150, 50); viewLB.setId("viewLB"); viewLB.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); BorderPane lbBorder = new BorderPane(); VBox lbBox = new VBox(); Scene lbScene = new Scene(lbBorder); Button lbBack = new Button("Start menu"); lbBox.getChildren().add(lbBack); lbBorder.setLeft(lbBox); lbBack.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); Label topText = new Label("Only shows scores higher than 100!"); topText.setStyle("-fx-font-size: 20pt;-fx-font-family: Segoe UI Semibold;"); viewLB.setOnAction( ActionEvent -> { HighscoreLeaderboard hBoard = gameManager.getHighscoreLeaderboard(); hBoard.setFocusTraversable(false); lbBorder.setCenter(hBoard); if (gameManager.getPlayer() != null) { Player client = gameManager.getPlayer(); Label you = new Label( "YOU: " + client.getNickname() + " [" + client.getId() + "] | Score: " + client.getHighscore()); you.setStyle("-fx-font-size: 15pt;-fx-font-family: Segoe UI Semibold;"); lbBorder.setBottom(you); } BorderPane.setMargin(hBoard, new Insets(12, 12, 12, 12)); lbBorder.setTop(topText); theStage.setScene(lbScene); lbBack.setOnAction( ActionEvent1 -> { theStage.setScene(startMenu); startMenuRoot.setLeft(mainButtonBox); BorderPane.setMargin(mainButtonBox, new Insets(350, 0, 0, 150)); }); }); joinBtn.setPrefSize(150, 50); tfNickname.setPrefSize(150, 20); joinBtn.setId("joinBtn"); joinBtn.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); lblNickname.setId("lblNickname"); lblNickname.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); createStart.setId("CreateStart"); createStart.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); loginStart.setId("loginStart"); loginStart.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); joinBtn.setOnAction( ActionEvent -> { Specializations spec; if (chooseRoller.isSelected()) { spec = Specializations.ROLLER; } else if (chooseHeavy.isSelected()) { spec = Specializations.HEAVY; } else // Blaster is default, if something goes wrong with radio // buttons { spec = Specializations.BLASTER; } theStage.setScene(gameScene); gameManager.joinAsGuest(gameBox, tfNickname.getText(), spec); gameManager.getMap().addObserver(this); gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage)); gameBox.requestFocus(); }); tfNickname.setOnAction( ActionEvent -> { Specializations spec; if (chooseRoller.isSelected()) { spec = Specializations.ROLLER; } else if (chooseHeavy.isSelected()) { spec = Specializations.HEAVY; } else // Blaster is default, if something goes wrong with radio // buttons { spec = Specializations.BLASTER; } theStage.setScene(gameScene); gameManager.joinAsGuest(gameBox, tfNickname.getText(), spec); gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage)); gameBox.requestFocus(); }); mainButtonBox.getChildren().add(lblNickname); mainButtonBox.getChildren().add(tfNickname); mainButtonBox.getChildren().add(specializationBox); mainButtonBox.getChildren().add(joinBtn); mainButtonBox.getChildren().add(loginStart); mainButtonBox.getChildren().add(createStart); mainButtonBox.getChildren().add(viewLB); startMenuRoot.setLeft(mainButtonBox); createStart.setOnAction( ActionEvent -> { VBox createAccountButtonBox = new VBox(); Label lblNickname2 = new Label("Nickname:"); TextField tfNickname2 = new TextField(); Label lblUserName = new Label("Name:"); TextField tfUserName = new TextField(); Label lblPassword = new Label("Password:"******"Repeat password:"******"Create account"); Button back = new Button("Start menu"); createBtn.setId("join-yyyyy"); createBtn.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); lblUserName.setId("join-game"); lblUserName.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); lblPassword.setId("join-game"); lblPassword.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); lblPassword2.setId("join-game"); lblPassword2.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); back.setId("join-game"); back.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); createAccountButtonBox.getChildren().add(lblNickname2); createAccountButtonBox.getChildren().add(tfNickname2); createAccountButtonBox.getChildren().add(lblUserName); createAccountButtonBox.getChildren().add(tfUserName); createAccountButtonBox.getChildren().add(lblPassword); createAccountButtonBox.getChildren().add(pf); createAccountButtonBox.getChildren().add(lblPassword2); createAccountButtonBox.getChildren().add(pf2); createAccountButtonBox.getChildren().add(createBtn); createAccountButtonBox.getChildren().add(back); startMenuRoot.setLeft(createAccountButtonBox); BorderPane.setMargin(createAccountButtonBox, new Insets(350, 0, 0, 150)); createBtn.setOnAction( ActionEvent1 -> { gameManager.createAccount( tfUserName.getText(), tfNickname2.getText(), pf.getText().toCharArray(), pf2.getText().toCharArray()); startMenuRoot.setLeft(mainButtonBox); BorderPane.setMargin(mainButtonBox, new Insets(350, 0, 0, 150)); }); back.setOnAction( ActionEvent1 -> { startMenuRoot.setLeft(mainButtonBox); BorderPane.setMargin(mainButtonBox, new Insets(350, 0, 0, 150)); }); }); loginStart.setOnAction( ActionEvent -> { VBox loginButtonBox = new VBox(); Button logInBtn = new Button("Log in"); Label lblUserName2 = new Label("Name:"); TextField tfUserName2 = new TextField(); Label lblPassword2 = new Label("Password:"******"Start Menu"); logInBtn.setId("join-game"); logInBtn.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); back2.setId("join-game"); back2.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); loginButtonBox.getChildren().add(lblUserName2); loginButtonBox.getChildren().add(tfUserName2); loginButtonBox.getChildren().add(lblPassword2); loginButtonBox.getChildren().add(pf3); loginButtonBox.getChildren().add(logInBtn); loginButtonBox.getChildren().add(back2); startMenuRoot.setLeft(loginButtonBox); BorderPane.setMargin(loginButtonBox, new Insets(350, 0, 0, 150)); logInBtn.setOnAction( ActionEvent1 -> { // TODO login }); back2.setOnAction( ActionEvent1 -> { startMenuRoot.setLeft(mainButtonBox); BorderPane.setMargin(mainButtonBox, new Insets(350, 0, 0, 150)); }); }); BorderPane.setMargin(mainButtonBox, new Insets(350, 0, 0, 150)); Button quitBtn = new Button("Quit game"); quitBtn.setPrefSize(80, 40); quitBtn.setId("quit-game"); quitBtn.setOnAction( ActionEvent -> { gameManager.quitGame(); theStage.setScene(startMenu); }); canvas = new Canvas(CANVAS_START_WIDTH, CANVAS_START_HEIGHT); gameBox.setCenter(canvas); BorderPane.setAlignment(canvas, Pos.TOP_LEFT); gameBox.setBottom(quitBtn); BorderPane.setAlignment(quitBtn, Pos.TOP_LEFT); theStage.show(); }
public <T extends Object> void revealElement( final T element, final EntryCall<? super T> entryCall, final IEditorPart editor) { final Runnable _function = () -> { try { Scene _scene = this.canvas.getScene(); double _width = _scene.getWidth(); boolean _equals = (_width == 0); if (_equals) { Scene _scene_1 = this.canvas.getScene(); ReadOnlyDoubleProperty _widthProperty = _scene_1.widthProperty(); final ChangeListener<Number> _function_1 = new ChangeListener<Number>() { @Override public void changed( final ObservableValue<? extends Number> p, final Number o, final Number n) { Scene _scene = FXDiagramTab.this.canvas.getScene(); ReadOnlyDoubleProperty _widthProperty = _scene.widthProperty(); _widthProperty.removeListener(this); FXDiagramTab.this.<T>revealElement(element, entryCall, editor); } }; _widthProperty.addListener(_function_1); } else { Scene _scene_2 = this.canvas.getScene(); double _height = _scene_2.getHeight(); boolean _equals_1 = (_height == 0); if (_equals_1) { Scene _scene_3 = this.canvas.getScene(); ReadOnlyDoubleProperty _heightProperty = _scene_3.heightProperty(); final ChangeListener<Number> _function_2 = new ChangeListener<Number>() { @Override public void changed( final ObservableValue<? extends Number> p, final Number o, final Number n) { Scene _scene = FXDiagramTab.this.canvas.getScene(); ReadOnlyDoubleProperty _heightProperty = _scene.heightProperty(); _heightProperty.removeListener(this); FXDiagramTab.this.<T>revealElement(element, entryCall, editor); } }; _heightProperty.addListener(_function_2); } else { this.<T>doRevealElement(element, entryCall, editor); } } } catch (final Throwable _t) { if (_t instanceof Exception) { final Exception exc = (Exception) _t; exc.printStackTrace(); Display _current = Display.getCurrent(); Shell _activeShell = _current.getActiveShell(); StringConcatenation _builder = new StringConcatenation(); _builder.append("Error showing element in FXDiagram:"); _builder.newLine(); String _message = exc.getMessage(); _builder.append(_message, ""); _builder.newLineIfNotEmpty(); _builder.append("See log for details."); _builder.newLine(); MessageDialog.openError(_activeShell, "Error", _builder.toString()); } else { throw Exceptions.sneakyThrow(_t); } } }; Platform.runLater(_function); }
@Override public void start(Stage primaryStage) { primaryStage.setTitle("Chapter 15-16 Adding Tabs to a UI"); Group root = new Group(); Scene scene = new Scene(root, 400, 250, Color.WHITE); TabPane tabPane = new TabPane(); MenuBar menuBar = new MenuBar(); EventHandler<ActionEvent> action = changeTabPlacement(tabPane); Menu menu = new Menu("Tab Side"); MenuItem left = new MenuItem("Left"); left.setOnAction(action); menu.getItems().add(left); MenuItem right = new MenuItem("Right"); right.setOnAction(action); menu.getItems().add(right); MenuItem top = new MenuItem("Top"); top.setOnAction(action); menu.getItems().add(top); MenuItem bottom = new MenuItem("Bottom"); bottom.setOnAction(action); menu.getItems().add(bottom); menuBar.getMenus().add(menu); BorderPane borderPane = new BorderPane(); // generate 10 tabs for (int i = 0; i < 10; i++) { Tab tab = new Tab(); tab.setText("Tab" + i); HBox hbox = new HBox(); hbox.getChildren().add(new Label("Tab" + i)); hbox.setAlignment(Pos.CENTER); tab.setContent(hbox); tabPane.getTabs().add(tab); } // add tab pane borderPane.setCenter(tabPane); // bind to take available space borderPane.prefHeightProperty().bind(scene.heightProperty()); borderPane.prefWidthProperty().bind(scene.widthProperty()); // added menu bar borderPane.setTop(menuBar); // add border Pane root.getChildren().add(borderPane); primaryStage.setScene(scene); primaryStage.show(); }
@Override public void start(Stage stage) { DropShadow dropShadow = new DropShadow(10.0, Color.rgb(150, 50, 50, .688)); dropShadow.setOffsetX(4); dropShadow.setOffsetY(6); StackPane stackPane = new StackPane(); stackPane.setAlignment(Pos.CENTER); stackPane.setEffect(dropShadow); Rectangle rectangle = new Rectangle(100, 50, Color.LEMONCHIFFON); rectangle.setArcWidth(30); rectangle.setArcHeight(30); Text text = new Text(); text.setFont(Font.font("Tahoma", FontWeight.BOLD, 18)); stackPane.getChildren().addAll(rectangle, text); final Scene scene = new Scene(stackPane, 400, 200, Color.LIGHTSKYBLUE); stage.setTitle("Custom Binding"); rectangle.widthProperty().bind(scene.widthProperty().divide(2)); rectangle.heightProperty().bind(scene.heightProperty().divide(2)); DoubleBinding opacityBinding = new DoubleBinding() { { // List the dependencies with super.bind() super.bind(scene.widthProperty(), scene.heightProperty()); } @Override protected double computeValue() { // Return the computed value double opacity = (scene.getWidth() + scene.getHeight()) / 1000; return (opacity > 1.0) ? 1.0 : opacity; } }; rectangle.opacityProperty().bind(opacityBinding); text.textProperty().bind((Bindings.format("opacity = %.2f", opacityBinding))); ObjectBinding<Color> colorBinding = new ObjectBinding<Color>() { { super.bind(scene.fillProperty()); } @Override protected Color computeValue() { if (scene.getFill() instanceof Color) { return ((Color) scene.getFill()).darker(); } else { return Color.GRAY; } } }; text.fillProperty().bind(colorBinding); stage.setScene(scene); stage.show(); }
@Override public void start(Stage primaryStage) { /* * Es recomendable usar un grupo de nodos como raiz de la escena. * El tamaño del grupo depende del tamaño de los nodos. */ Group root = new Group(); // Pinto una escena negra de 800 * 600 Scene scene = new Scene(root, 800, 600, Color.BLACK); primaryStage.setScene(scene); // A continuacion vamos a pintar 30 circulos Group circles = new Group(); for (int i = 0; i < 30; i++) { // Creo un criculo con un radio de 150, color blanco y opacidad del 5% Circle circle = new Circle(150, Color.web("white", 0.05)); // Creo un borde alrededor del circulo circle.setStrokeType(StrokeType.OUTSIDE); // Color del borde del circulo y opacidad circle.setStroke(Color.web("white", 0.16)); // ancho del borde exterior del circulo circle.setStrokeWidth(4); // Añado el grupo de circulos a la raiz (root) circles.getChildren().add(circle); } Rectangle colors = new Rectangle( scene.getWidth(), scene.getHeight(), new LinearGradient( 0f, 1f, 1f, 0f, true, CycleMethod.NO_CYCLE, new Stop[] { new Stop(0, Color.web("#f8bd55")), new Stop(0.14, Color.web("#c0fe56")), new Stop(0.28, Color.web("#5dfbc1")), new Stop(0.43, Color.web("#64c2f8")), new Stop(0.57, Color.web("#be4af7")), new Stop(0.71, Color.web("#ed5fc2")), new Stop(0.85, Color.web("#ef504c")), new Stop(1, Color.web("#f2660f")), })); colors.widthProperty().bind(scene.widthProperty()); colors.heightProperty().bind(scene.heightProperty()); Group blendModeGroup = new Group( new Group(new Rectangle(scene.getWidth(), scene.getHeight(), Color.BLACK), circles), colors); colors.setBlendMode(BlendMode.OVERLAY); root.getChildren().add(blendModeGroup); // Añadimos un efecto de desenfocado a los circulos circles.setEffect(new BoxBlur(10, 10, 3)); Timeline timeline = new Timeline(); for (Node circle : circles.getChildren()) { timeline .getKeyFrames() .addAll( new KeyFrame( Duration.ZERO, // set start position at 0 new KeyValue(circle.translateXProperty(), random() * 800), new KeyValue(circle.translateYProperty(), random() * 600)), new KeyFrame( new Duration(40000), // set end position at 40s new KeyValue(circle.translateXProperty(), random() * 800), new KeyValue(circle.translateYProperty(), random() * 600))); } timeline.play(); primaryStage.show(); }