Repository: incubator-ignite Updated Branches: refs/heads/ignite-32 0d907c4e0 -> 2b0a2d130
# IGNITE-32 WIP: Refactoring message box. Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/5e7b9cdd Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/5e7b9cdd Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/5e7b9cdd Branch: refs/heads/ignite-32 Commit: 5e7b9cdd0ed5869415d0c1de5b88adee7e0f73dc Parents: 0d907c4 Author: AKuznetsov <akuznet...@gridgain.com> Authored: Sun Dec 28 14:23:25 2014 +0700 Committer: AKuznetsov <akuznet...@gridgain.com> Committed: Sun Dec 28 14:23:25 2014 +0700 ---------------------------------------------------------------------- .../org/apache/ignite/schema/ui/Controls.java | 72 +++++++ .../org/apache/ignite/schema/ui/MessageBox.java | 206 ++++++++++--------- 2 files changed, 184 insertions(+), 94 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5e7b9cdd/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/Controls.java ---------------------------------------------------------------------- diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/Controls.java b/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/Controls.java index 954bdb1..d1a1cd2 100644 --- a/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/Controls.java +++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/Controls.java @@ -10,12 +10,47 @@ package org.apache.ignite.schema.ui; import javafx.event.*; +import javafx.geometry.*; import javafx.scene.control.*; +import javafx.scene.image.*; +import javafx.scene.layout.*; +import javafx.scene.text.*; /** * Utility class to create controls. */ public class Controls { + /** */ + public static final Insets DFLT_PADDING = new Insets(10, 10, 10, 10); + + /** + * Create new {@code HBox} with default padding. + * + * @param spacing Amount of horizontal space between each child. + * @return New {@code HBox} instance. + */ + public static HBox hBox(int spacing) { + HBox hb = new HBox(spacing); + + hb.setPadding(DFLT_PADDING); + + return hb; + } + + /** + * Create new {@code VBox} with default padding. + * + * @param spacing Amount of horizontal space between each child. + * @return New {@code VBox} instance. + */ + public static VBox vBox(int spacing) { + VBox vb = new VBox(spacing); + + vb.setPadding(DFLT_PADDING); + + return vb; + } + /** * Create button. * @@ -47,9 +82,46 @@ public class Controls { } /** + * Create text field. + * * @return New text field instance. */ public static TextField textField() { return new TextField(); } + + /** + * Create static text. + * + * @param text Text to show. + * @param wrap Text wrapping width. + * @return New text instance. + */ + public static Text text(String text, int wrap) { + Text t = new Text(text); + + t.setWrappingWidth(wrap); + + return t; + } + + /** + * Create image view. + * + * @param imgFileName Image filename. + * @return New image view instance. + */ + public static ImageView imageView(String imgFileName, int sz) { + return new ImageView(image(imgFileName, sz)); + } + + /** + * Gets image by its filename. + * + * @param imgFileName Image filename. + */ + public static Image image(String imgFileName, int sz) { + return new Image(Controls.class.getClassLoader() + .getResourceAsStream(String.format("media/%1$s_%2$dx%2$d.png", imgFileName, sz))); + } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5e7b9cdd/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/MessageBox.java ---------------------------------------------------------------------- diff --git a/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/MessageBox.java b/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/MessageBox.java index 359f0af..989f8e3 100644 --- a/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/MessageBox.java +++ b/modules/schema-load/src/main/java/org/apache/ignite/schema/ui/MessageBox.java @@ -12,118 +12,136 @@ package org.apache.ignite.schema.ui; import javafx.event.*; import javafx.geometry.*; import javafx.scene.*; -import javafx.scene.control.*; -import javafx.scene.image.*; import javafx.scene.layout.*; -import javafx.scene.text.*; import javafx.stage.*; -import static org.apache.ignite.schema.util.SchemaUtils.*; +import static org.apache.ignite.schema.ui.Controls.*; /** * Message box functionality. */ -public class MessageBox { - /** */ - public enum Option {NO, YES, CANCEL} - - private static Option result = Option.CANCEL; - - private static ImageView icon = new ImageView(); - - static class Dialog extends Stage { - public Dialog(String title, Stage owner, Scene scene, String iconFile) { - setTitle(title); - initStyle(StageStyle.UTILITY); - initModality(Modality.APPLICATION_MODAL); - initOwner(owner); - setResizable(false); - setScene(scene); - icon.setImage(image(iconFile, 48)); +public class MessageBox extends Stage { + /** Return value if YES is chosen. */ + public static final int YES_OPTION = 0; + /** Return value if NO is chosen. */ + public static final int NO_OPTION = 1; + /** Return value if CANCEL is chosen. */ + public static final int CANCEL_OPTION = 2; + + /** Dialog result. */ + private int res = CANCEL_OPTION; + + /** + * Create message box. + * + * @param owner Owner window. + * @param title Title text. + * @param msg Message to show. + * @param iconFile Message icon. + * @param yesNo If {@code true} show "yes" and "no" buttons + * otherwise show "ok" button. + */ + private MessageBox(Stage owner, String title, String msg, String iconFile, boolean yesNo) { + setTitle(title); + initStyle(StageStyle.UTILITY); + initModality(Modality.APPLICATION_MODAL); + initOwner(owner); + setResizable(false); + + VBox vb = vBox(10); + + setScene(new Scene(vb)); + + HBox btns = hBox(10); + btns.setAlignment(Pos.CENTER); + + if (yesNo) { + res = NO_OPTION; + + btns.getChildren().addAll(button("Yes", new EventHandler<ActionEvent>() { + @Override public void handle(ActionEvent e) { + res = YES_OPTION; + + close(); + } + }), button("No", new EventHandler<ActionEvent>() { + @Override public void handle(ActionEvent e) { + res = NO_OPTION; + + close(); + } + })); } + else + btns.getChildren().add(button("OK", new EventHandler<ActionEvent>() { + @Override public void handle(ActionEvent e) { + close(); + } + })); - public void showDialog() { - sizeToScene(); - centerOnScreen(); - showAndWait(); - } - } - - static class Message extends Text { - public Message(String msg) { - super(msg); - setWrappingWidth(250); - } - } + HBox hb = hBox(10); + hb.getChildren().addAll(imageView(iconFile, 48), text(msg, 250)); - public static Option showConfirmDialog(Stage owner, String message, String title) { - VBox vb = newVBox(10); - - Scene scene = new Scene(vb); - - final Dialog dial = new Dialog(title, owner, scene, "question"); - - Button yesButton = new Button("Yes"); - yesButton.setOnAction(new EventHandler<ActionEvent>() { - @Override public void handle(ActionEvent e) { - dial.close(); - result = Option.YES; - } - }); - - Button noButton = new Button("No"); - noButton.setOnAction(new EventHandler<ActionEvent>() { - @Override public void handle(ActionEvent e) { - dial.close(); - result = Option.NO; - } - }); - - BorderPane bp = new BorderPane(); - HBox buttons = new HBox(); - buttons.setAlignment(Pos.CENTER); - buttons.setSpacing(10); - buttons.getChildren().addAll(yesButton, noButton); - bp.setCenter(buttons); - HBox msg = new HBox(); - msg.setSpacing(5); - msg.getChildren().addAll(icon, new Message(message)); - vb.getChildren().addAll(msg, bp); - dial.showDialog(); - - return result; + vb.getChildren().addAll(hb, btns); } + /** + * Show modal dialog. + */ + public void showDialog() { + sizeToScene(); - private static void showDialog(Stage owner, String title, String msg, String iconFile) { - VBox vb = newVBox(10); - Scene scene = new Scene(vb); + centerOnScreen(); - final Dialog dial = new Dialog(title, owner, scene, iconFile); - - Button okButton = new Button("OK"); - okButton.setAlignment(Pos.CENTER); - okButton.setOnAction(new EventHandler<ActionEvent>() { - @Override public void handle(ActionEvent e) { - dial.close(); - } - }); - - BorderPane bp = new BorderPane(); - bp.setCenter(okButton); + showAndWait(); + } - HBox hb = new HBox(); - hb.setSpacing(5); - hb.getChildren().addAll(icon, new Message(msg)); - vb.getChildren().addAll(hb, bp); + /** + * Show message in modal dialog. + * + * @param owner Owner window. + * @param title Title text. + * @param msg Message to show. + * @param iconFile Message icon. + * @param yesNo If {@code true} show "yes" and "no" buttons + * otherwise show "ok" button. + * @return Option selected by the user. + */ + private static int showDialog(Stage owner, String title, String msg, String iconFile, boolean yesNo) { + MessageBox dlg = new MessageBox(owner, title, msg, iconFile, yesNo); + + dlg.showDialog(); + + return dlg.res; + } - dial.showDialog(); + /** + * Show confirmation dialog. + * + * @param owner Owner window. + * @param msg Message to show. + * @return Option selected by the user. + */ + public static int confirmDialog(Stage owner, String msg) { + return showDialog(owner, "Confirmation", msg, "question", true); } - public static void showInformationDialog(Stage owner, String title, String msg) { - showDialog(owner, title, msg, "information"); + /** + * Show information dialog. + * + * @param owner Owner window. + * @param msg Message to show. + */ + public static void informationDialog(Stage owner, String msg) { + showDialog(owner, "Information", msg, "information", false); } - public static void showErrorDialog(Stage owner, String msg) { - showDialog(owner, "Error", msg, "error"); + /** + * Show error dialog. + * + * @param owner Owner window. + * @param msg Message to show. + */ + public static void errorDialog(Stage owner, String msg) { + showDialog(owner, "Error", msg, "error", false); } }