Skip to content
Permalink
Browse files

code clean up along with adding the INFO severity; changed fx-effect …

…color for INFO severity to be skyblue
  • Loading branch information...
Mason Chou Mason Chou
Mason Chou authored and Mason Chou committed Nov 5, 2019
1 parent d482d29 commit a209b34e674e8be2aae258b0f99d607aba76cf34
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2014, ControlsFX
* Copyright (c) 2014, 2019 ControlsFX
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -63,9 +63,9 @@

public class HelloValidation extends ControlsFXSample {

TextField textField = new TextField();
private TextField textField = new TextField();
private ValidationSupport validationSupport = new ValidationSupport();


@Override public String getSampleName() {
return "Component Validation";
}
@@ -78,8 +78,6 @@
return "Component Validation";
}

ValidationSupport validationSupport = new ValidationSupport();

@Override public Node getPanel(final Stage stage) {
GridPane root = new GridPane();
root.setVgap(10);
@@ -94,18 +92,11 @@
}
});


// final ListView<ValidationMessage> messageList = new ListView<>();
// validationSupport.validationResultProperty().addListener( (o, oldValue, validationResult) -> {
// messageList.getItems().setAll(validationResult.getMessages());
// }
// );


int row = 0;

// text field
validationSupport.registerValidator(textField, Validator.createEmptyValidator("Text is required"));

root.add(new Label("TextField"), 0, row);
root.add(textField, 1, row);
GridPane.setHgrow(textField, Priority.ALWAYS);
@@ -114,7 +105,12 @@
row++;
ComboBox<String> combobox = new ComboBox<String>();
combobox.getItems().addAll("Item A", "Item B", "Item C");
validationSupport.registerValidator(combobox, Validator.createEmptyValidator( "ComboBox Selection required"));
validationSupport.registerValidator(combobox, (Control c, String newValue) ->
ValidationResult.fromErrorIf(combobox, "ComboBox Selection required", newValue == null || newValue.isEmpty())
.addInfoIf(combobox, "Item A is the first item", "Item A".equals(newValue))
.addInfoIf(combobox, "Item B is the second item", "Item B".equals(newValue))
.addInfoIf(combobox, "Item C is the third item", "Item C".equals(newValue))
);

root.add(new Label("ComboBox"), 0, row);
root.add(combobox, 1, row);
@@ -128,14 +124,14 @@

root.add(new Label("ChoiceBox"), 0, row);
root.add(choiceBox, 1, row);
GridPane.setHgrow(combobox, Priority.ALWAYS);
GridPane.setHgrow(choiceBox, Priority.ALWAYS);

//checkbox
row++;
CheckBox checkBox = new CheckBox();
validationSupport.registerValidator(checkBox, (Control c, Boolean newValue) ->
ValidationResult.fromErrorIf( c, "Checkbox should be checked", !newValue)
);
validationSupport.registerValidator(checkBox, (Control c, Boolean newValue) ->
ValidationResult.fromErrorIf(c, "Checkbox should be checked", !newValue));

root.add(new Label("CheckBox"), 0, row);
root.add(checkBox, 1, row);
GridPane.setHgrow(checkBox, Priority.ALWAYS);
@@ -144,46 +140,37 @@
row++;
Slider slider = new Slider(-50d, 50d, -10d);
slider.setShowTickLabels(true);
validationSupport.registerValidator(slider, (Control c, Double newValue) ->
ValidationResult.fromErrorIf( slider, "Slider value should be > 0", newValue <= 0 ));
validationSupport.registerValidator(slider, (Control c, Double newValue) ->
ValidationResult.fromErrorIf(slider, "Slider value should be > 0", newValue <= 0));

root.add(new Label("Slider"), 0, row);
root.add(slider, 1, row);
GridPane.setHgrow(checkBox, Priority.ALWAYS);
GridPane.setHgrow(slider, Priority.ALWAYS);

// color picker
row++;
ColorPicker colorPicker = new ColorPicker(Color.RED);
validationSupport.registerValidator(colorPicker,
validationSupport.registerValidator(colorPicker,
Validator.createEqualsValidator("Color should be WHITE or BLACK", Arrays.asList(Color.WHITE, Color.BLACK)));

root.add(new Label("Color Picker"), 0, row);
root.add(colorPicker, 1, row);
GridPane.setHgrow(checkBox, Priority.ALWAYS);
GridPane.setHgrow(colorPicker, Priority.ALWAYS);

// date picker
row++;
DatePicker datePicker = new DatePicker();
validationSupport.registerValidator(datePicker, false, (Control c, LocalDate newValue) ->
ValidationResult.fromWarningIf( datePicker, "The date should be today", !LocalDate.now().equals(newValue)));
validationSupport.registerValidator(datePicker, false, (Control c, LocalDate newValue) ->
ValidationResult.fromWarningIf(datePicker, "The date should be today", !LocalDate.now().equals(newValue)));

root.add(new Label("Date Picker"), 0, row);
root.add(datePicker, 1, row);
GridPane.setHgrow(checkBox, Priority.ALWAYS);

// // validation results
// row++;
// TitledPane pane = new TitledPane("Validation Results", messageList);
// pane.setCollapsible(false);
// root.add(pane, 0, row, 2, 1);
// GridPane.setHgrow(pane, Priority.ALWAYS);
GridPane.setHgrow(datePicker, Priority.ALWAYS);

//root.setTop(grid);
ScrollPane scrollPane = new ScrollPane(root);
return scrollPane;
}


@Override public Node getControlPanel() {
GridPane grid = new GridPane();
grid.setVgap(10);
@@ -195,7 +182,7 @@
ValidationDecoration compoundDecorator = new CompoundValidationDecoration(cssDecorator, iconDecorator);

int row = 0;

// --- validation decorator
Callback<ListView<ValidationDecoration>, ListCell<ValidationDecoration>> cellFactory = listView -> new ListCell<ValidationDecoration>() {
@Override protected void updateItem(ValidationDecoration decorator, boolean empty) {
@@ -229,14 +216,12 @@
grid.add(validationDecoratorLabel, 0, row);
grid.add(decoratorBox, 1, row);
GridPane.setHgrow(decoratorBox, Priority.ALWAYS);

row++;
ToggleButton btnToggleRequired = new ToggleButton("Toggle TextField required status");
btnToggleRequired.setSelected(ValidationSupport.isRequired(textField));
btnToggleRequired.setOnAction(e -> {
// boolean required = ValidationSupport.isRequired(textField);
System.out.println("Is required: " + btnToggleRequired.isSelected());
ValidationSupport.setRequired(textField, btnToggleRequired.isSelected());
ValidationSupport.setRequired(textField, btnToggleRequired.isSelected());
});
grid.add(btnToggleRequired, 1, row, 1, 1);

@@ -246,5 +231,4 @@
public static void main(String[] args) {
launch(args);
}

}
@@ -7,5 +7,5 @@
}

.info {
-fx-effect: dropshadow(three-pass-box, rgba(196, 208, 239, 0.7), 14, 0, 0, 0);
-fx-effect: dropshadow(three-pass-box, skyblue, 14, 0, 0, 0);
}

0 comments on commit a209b34

Please sign in to comment.
You can’t perform that action at this time.