package actions.login; import javafx.event.ActionEvent; import javafx.event.Event; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Group; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.scene.paint.CycleMethod; import javafx.scene.paint.LinearGradient; import javafx.scene.paint.RadialGradient; import javafx.scene.paint.Stop; import javafx.scene.shape.Circle; import javafx.scene.shape.CircleBuilder; import javafx.scene.shape.LineTo; import javafx.scene.shape.MoveTo; import javafx.scene.shape.Path; import javafx.scene.shape.QuadCurveTo; import javafx.scene.shape.Rectangle; import javafx.scene.shape.StrokeLineJoin; import javafx.stage.Modality; import javafx.stage.Stage; import javafx.stage.StageStyle; public class LoginDialog extends Stage { private static final int DIALOG_WIDHT = 300; public LoginDialog(Stage owner) { super(); initOwner(owner); initModality(Modality.APPLICATION_MODAL); setTitle("Login"); init(); } private void init() { Group root = new Group(); Scene rootScene = new Scene(root, Color.TRANSPARENT); setScene(rootScene); initStyle(StageStyle.TRANSPARENT); BorderPane layout = new BorderPane(); layout.setTop(getTitlePane()); layout.setCenter(initLoginBox()); layout.setBottom(initButtons()); root.getChildren().add(layout); setScene(rootScene); } /** * Top panel with cloud * * @return */ private Node getTitlePane() { StackPane stack = new StackPane(); Rectangle background = getTopBackground(); Path path = getCloud(); Circle border = getCloseCircle(); stack.getChildren().addAll(background, path); stack.getChildren().add(border); return stack; } private Circle getCloseCircle() { Circle border = CircleBuilder.create().centerX(30).centerY(30) .radius(10).build(); border.setStroke(Color.WHITESMOKE); border.setStrokeWidth(3.0); border.setFill(new RadialGradient(0, 2*Math.PI, 0, 0, 5, true, CycleMethod.NO_CYCLE, new Stop[] { new Stop(0, Color.BLACK), new Stop(1, Color.WHITESMOKE) })); StackPane.setAlignment(border, Pos.TOP_RIGHT); border.setOnMouseClicked(new EventHandler() { @Override public void handle(Event arg0) { close(); hide(); } }); return border; } /* * top panel background */ private Rectangle getTopBackground() { Rectangle background = new Rectangle(DIALOG_WIDHT, 150, Color.ORANGE); background.setArcHeight(80.0); background.setArcWidth(80.0); return background; } private Path getCloud() { Path path = new Path(); path.setStrokeWidth(3.0); Stop[] stops = new Stop[] { new Stop(0, Color.ORANGE), new Stop(1, Color.WHITESMOKE) }; LinearGradient gradient = new LinearGradient(0, 0, 1, 0, true, CycleMethod.NO_CYCLE, stops); path.setFill(gradient); path.setStroke(gradient); MoveTo start = new MoveTo(); start.setX(0); start.setY(125); QuadCurveTo firstQuad = new QuadCurveTo(); firstQuad.setX(50); firstQuad.setY(80); firstQuad.setControlX(10); firstQuad.setControlY(25); QuadCurveTo secondQuad = new QuadCurveTo(); secondQuad.setX(100); secondQuad.setY(80); secondQuad.setControlX(75); secondQuad.setControlY(0); QuadCurveTo thirdQuad = new QuadCurveTo(); thirdQuad.setX(150); thirdQuad.setY(125); thirdQuad.setControlX(140); thirdQuad.setControlY(25); LineTo line = new LineTo(); line.setX(0); line.setY(125); path.getElements().add(start); path.getElements().add(firstQuad); path.getElements().add(secondQuad); path.getElements().add(thirdQuad); path.getElements().add(line); path.setSmooth(true); path.setStrokeLineJoin(StrokeLineJoin.BEVEL); return path; } private HBox initButtons() { HBox buttons = new HBox(); buttons.setAlignment(Pos.CENTER_RIGHT); buttons.getChildren().add(new Button("Login")); buttons.setPadding(new Insets(10)); Button cancel = new Button("Cancel"); cancel.setOnAction(new EventHandler() { @Override public void handle(ActionEvent arg0) { // TODO Auto-generated method stub close(); } }); buttons.getChildren().add(cancel); return buttons; } private VBox initLoginBox() { VBox loginBox = new VBox(); loginBox.getChildren().add(new Label("Username")); loginBox.getChildren().add(new TextField("Username")); loginBox.getChildren().add(new Label("Password")); loginBox.getChildren().add(new TextField("Password")); loginBox.setPadding(new Insets(10)); return loginBox; } }