Created
February 15, 2017 11:23
-
-
Save PanAeon/fa71fd7eda143307276be0086bbfb16b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class JavafxDslTest extends Application implements JavaFxDsl { | |
public static void main(String[] args) { | |
launch(JavafxDslTest.class); | |
} | |
@Bind(id = "pill-left") | |
private ToggleButton fromExisting; | |
@Bind(id = "pill-right") | |
private ToggleButton fromNew; | |
@Override | |
public void start(Stage stage) throws Exception { | |
ToggleGroup group = new ToggleGroup(); | |
@SuppressWarnings("unchecked") | |
StackPane root = | |
stackPane( | |
stackPane( | |
vbox( | |
label("Создать новий шаблон").withStyleclass("dialog-header-text"), | |
gridPane( | |
hbox( | |
toggleButton("Новый", id -> "pill-left").fix(x -> x.setToggleGroup(group)), | |
toggleButton("Копия", id -> "pill-right").fix(x -> { | |
x.setToggleGroup(group); | |
group.selectToggle(fromExisting); // check that fix runs after init | |
}) | |
).fix(x -> setConstraints(x, 1, 0)), | |
label("Template:").fix(l -> setConstraints(l, 0, 1)), | |
choiceBox(items -> FXCollections | |
.observableArrayList(Arrays.asList("1", "2", "3", "4", "5")) | |
.sorted()).fix(cb -> setConstraints(cb, 1, 1)), | |
label("Provider:").fix(l -> setConstraints(l, 0, 2)), | |
hbox( | |
choiceBox( | |
items -> FXCollections | |
.observableArrayList(Arrays.asList("1", "2", "3", "4", "5")) | |
.sorted() | |
), | |
hyperlink("Add new") | |
) | |
.attrs(spacing -> 5) | |
.fix(x -> setConstraints(x, 1, 2)), | |
label("Template Id:").fix(x -> setConstraints(x, 0, 3)), | |
textField().fix(x -> setConstraints(x, 1, 3)), | |
label("choose grid:").fix(x -> setConstraints(x, 0, 4)), | |
hbox( | |
label("empty"), | |
button("select file") | |
).attrs(spacing -> 5.0).fix(x -> setConstraints(x, 1, 4)) | |
).fix(wizardForm -> { | |
wizardForm.getColumnConstraints().add(new ColumnConstraints(150)); // column 0 is 100 wide | |
wizardForm.getColumnConstraints().add(new ColumnConstraints(300)); | |
}) | |
.attrs(prefWidth -> 300.0, prefHeight -> 150.0, vgap -> 5.0), | |
anchorPane( | |
button("proceed").fix(b -> { | |
AnchorPane.setRightAnchor(b, 0.0); | |
AnchorPane.setBottomAnchor(b, 0.0); | |
}), | |
button("cancel").fix(b -> { | |
AnchorPane.setRightAnchor(b, 100.0); | |
AnchorPane.setBottomAnchor(b, 0.0); | |
}) | |
) | |
) | |
.attrs( | |
spacing -> 10, | |
maxWidth -> 450.0 + 80.0, | |
maxHeight -> 300.0 | |
) | |
.withStyleclass("dialog-content") | |
) | |
.attrs(padding -> new Insets(10)) | |
) | |
.attrs(padding -> new Insets(10)) | |
.buildAndBind(this); | |
// TODO: couldn't capture local variables.... | |
Scene scene = new Scene(root); | |
stage.setScene(scene); | |
scene.getStylesheets().add("stylesheet.css"); | |
stage.show(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NewGridWizard extends Application { | |
public StackPane topPane; | |
public StackPane newTemplateWizard; | |
private void createNewTemplateWizard() { | |
this.newTemplateWizard = new StackPane(); | |
newTemplateWizard.setPadding(new Insets(10)); | |
topPane.getChildren().add(newTemplateWizard); | |
VBox wizardContent = new VBox(10); | |
wizardContent.getStyleClass().add("dialog-content"); | |
wizardContent.setMaxSize(450.0 + 80.0, 300.0); | |
//wizardContent.setPrefSize(450.0, 300.0); | |
Label label = new Label("Создать новий шаблон"); | |
label.getStyleClass().add("dialog-header-text"); | |
newTemplateWizard.getChildren().add(wizardContent); // -- | |
GridPane wizardForm = new GridPane(); | |
wizardForm.getColumnConstraints().add(new ColumnConstraints(150)); // column 0 is 100 wide | |
wizardForm.getColumnConstraints().add(new ColumnConstraints(300)); // column 1 is 200 wide | |
wizardForm.setVgap(5.0); | |
{ | |
ToggleButton fromNew = new ToggleButton("Новый"); | |
fromNew.setId("pill-left"); | |
ToggleButton fromExisting = new ToggleButton("Копия"); | |
fromExisting.setId("pill-right"); | |
ToggleGroup group = new ToggleGroup(); | |
fromNew.setToggleGroup(group); | |
fromExisting.setToggleGroup(group); | |
// select the first button to start with | |
group.selectToggle(fromNew); | |
HBox toggleButtons = new HBox(); | |
toggleButtons.getChildren().addAll(fromNew, fromExisting); | |
GridPane.setConstraints(toggleButtons, 1, 0); // -- | |
Label templateL = new Label("Template:"); | |
GridPane.setConstraints(templateL, 0, 1); | |
ChoiceBox<String> templateSelect = new ChoiceBox<>(FXCollections | |
.observableArrayList(Arrays.asList("1", "2", "3", "4", "5")) | |
.sorted()); | |
GridPane.setConstraints(templateSelect, 1, 1); | |
Label providerL = new Label("Provider:"); | |
GridPane.setConstraints(providerL, 0, 2); | |
HBox providerSelectBox = new HBox(5); | |
GridPane.setConstraints(providerSelectBox, 1, 2); | |
ChoiceBox<String> providerSelect = new ChoiceBox<>(FXCollections | |
.observableArrayList(Arrays.asList("1", "2", "3", "4", "5")) | |
.sorted()); | |
Hyperlink addProviderLink = new Hyperlink("Add new"); | |
providerSelectBox.getChildren().addAll(providerSelect, addProviderLink); | |
Label templateName = new Label("Template Id:"); | |
GridPane.setConstraints(templateName, 0, 3); | |
TextField templateNameTextField = new TextField(); | |
GridPane.setConstraints(templateNameTextField, 1, 3); | |
Label fileLabel = new Label("choose grid:"); | |
GridPane.setConstraints(fileLabel, 0, 4); | |
HBox fileHBox = new HBox(5); | |
GridPane.setConstraints(fileHBox, 1, 4); | |
Label fileNameLabel = new Label("empty"); | |
Button selectFileButton = new Button("Select file"); | |
fileHBox.getChildren().addAll(fileNameLabel, selectFileButton); | |
wizardForm.getChildren().addAll(toggleButtons, templateL, templateSelect, providerL, providerSelectBox, templateName, | |
templateNameTextField,fileLabel, fileHBox); | |
} | |
wizardForm.setPrefSize(300.0, 150.0); | |
AnchorPane wizardControls = new AnchorPane(); | |
Button proceed = new Button("Proceed"); | |
Button cancel = new Button("Cancel"); | |
AnchorPane.setRightAnchor(proceed, 0.0); | |
AnchorPane.setBottomAnchor(proceed, 0.0); | |
AnchorPane.setRightAnchor(cancel, 100.0); | |
AnchorPane.setBottomAnchor(cancel, 0.0); | |
wizardControls.getChildren().addAll(proceed, cancel); | |
wizardContent.getChildren().addAll(label, wizardForm, wizardControls); // -- | |
} | |
@Override | |
public void start(Stage stage) throws Exception { | |
topPane = new StackPane(); | |
topPane.setPadding(new Insets(10)); | |
createNewTemplateWizard(); | |
Scene scene = new Scene(topPane); | |
stage.setScene(scene); | |
scene.getStylesheets().add("stylesheet.css"); | |
stage.show(); | |
} | |
public static void main(String[] args) { | |
launch(NewGridWizard.class); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment