use of javafx.scene.control.TextField in project Smartcity-Smarthouse by TechnionYP5777.
the class SendMessageController method addDoubleField.
private void addDoubleField(String fieldName) {
Label label = new Label(fieldName + ":");
TextField lowerRange = new TextField(FROM), topRange = new TextField(TO);
HBox hb = new HBox(label, lowerRange, topRange);
hb.setSpacing(3);
lowerRange.focusedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> b, Boolean oldValue, Boolean newValue) {
if (// Focusing out
!newValue)
lowerRange.setStyle("-fx-border-color: " + (!validateInteger(lowerRange.getText()) ? "red" : "green"));
}
});
topRange.focusedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> b, Boolean oldValue, Boolean newValue) {
if (// Focusing out
!newValue)
topRange.setStyle("-fx-border-color: " + (!validateInteger(topRange.getText()) ? "red" : "green"));
}
});
VBox vbox = new VBox(label, hb);
vbox.setSpacing(5);
vbox.setPadding(new Insets(10, 0, 0, 10));
mainPane.getChildren().add(vbox);
consumers.add(l -> {
List<Double> input = new ArrayList<>();
try {
double lower = Double.parseDouble(lowerRange.getText()), top = Double.parseDouble(topRange.getText());
if (lower > top) {
this.encounterdIssue = true;
issues.add("in " + fieldName + " From must be less or equal to To");
} else {
input.add(lower);
input.add(top);
l.put(fieldName, input);
}
} catch (final Exception e) {
this.encounterdIssue = true;
issues.add("in " + fieldName + " Values must be Double!");
}
});
}
use of javafx.scene.control.TextField in project DistributedFractalNetwork by Budder21.
the class GradientMenus method displayLayerMenu.
/**
* Used to display the opacity editor that controls the opacity of a whole layer.
* @param t the tree item that connects to a layer whose opacity is being modified
* @return a new metalayer containing the layer's metadata
*/
public static MetaLayer displayLayerMenu(TreeItem<MetaLayer> t) {
Stage window = new Stage();
Slider opacityLevel = new Slider(0, 1, (Double) t.getValue().getOpacity());
Label opacityCaption = new Label("Opacity Level:");
Label opacityValue = new Label(Double.toString(opacityLevel.getValue()));
opacityValue.setText(String.format("%.2f", opacityLevel.getValue()));
opacityLevel.valueProperty().addListener(new ChangeListener<Number>() {
public void changed(ObservableValue<? extends Number> ov, Number old_val, Number new_val) {
DecimalFormat df = new DecimalFormat("0.00");
opacityValue.setText((df.format(opacityLevel.getValue())));
}
});
// Block events to other windows
window.initModality(Modality.APPLICATION_MODAL);
window.setTitle("Edit Layer");
window.setMinWidth(250);
window.setMinHeight(210);
VBox layout = new VBox(10);
Label name = new Label();
name.setText("Enter Name of Layer:");
TextField nameIn = new TextField();
nameIn.setPromptText("Layer Name");
nameIn.minWidthProperty().bind(window.minWidthProperty().divide(2));
nameIn.maxWidthProperty().bind(window.minWidthProperty().multiply(.75));
Label type = new Label();
type.setText("Select a Layer Type:");
ChoiceBox typeIn = new ChoiceBox();
typeIn.getItems().addAll(Layer.getLayerTypes());
typeIn.minWidthProperty().bind(window.minWidthProperty().divide(2));
typeIn.maxWidthProperty().bind(window.minWidthProperty().multiply(.75));
typeIn.getSelectionModel().selectFirst();
HBox hbox = new HBox();
Button closeButton = new Button("Submit");
closeButton.setOnAction(e -> window.close());
CheckBox delete = new CheckBox("Delete");
Canvas spacer = new Canvas();
spacer.setWidth(30);
Canvas push = new Canvas();
push.setWidth(50);
hbox.getChildren().addAll(push, closeButton, spacer, delete);
HBox opacityBox = new HBox();
opacityBox.maxWidthProperty().bind(window.minWidthProperty().multiply(.75));
opacityLevel.maxWidthProperty().bind(window.minWidthProperty().multiply(.75));
Canvas opacitySpacer = new Canvas();
opacitySpacer.setWidth(10);
opacityBox.getChildren().addAll(opacityCaption, opacitySpacer, opacityValue);
Canvas vspace = new Canvas();
vspace.setHeight(10);
layout.getChildren().addAll(name, nameIn, type, typeIn, opacityBox, opacityLevel, hbox, vspace);
layout.setAlignment(Pos.CENTER);
if (((MetaLayer) t.getValue()).getName() != null)
nameIn.setText(((MetaLayer) t.getValue()).getName());
if (((MetaLayer) t.getValue()).getType() != null) {
typeIn.getSelectionModel().select(((MetaLayer) t.getValue()).getType());
}
// Display window and wait for it to be closed before returning
Scene scene = new Scene(layout);
window.setScene(scene);
window.showAndWait();
if (delete.isSelected())
return new MetaLayer(nameIn.getText(), typeIn.getSelectionModel().getSelectedItem().toString(), opacityLevel.getValue(), true);
return new MetaLayer(nameIn.getText(), typeIn.getSelectionModel().getSelectedItem().toString(), opacityLevel.getValue());
}
use of javafx.scene.control.TextField in project DistributedFractalNetwork by Budder21.
the class NetworkCreationTool method displayDialog2.
private Pair<Integer, Integer> displayDialog2() {
Dialog<Pair<String, String>> dialog2 = new Dialog<>();
dialog2.setTitle("Create Network");
dialog2.setHeaderText("Step 2");
dialog2.setContentText("Choose an image resolution:");
dialog2.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
GridPane grid = new GridPane();
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(20, 150, 10, 10));
TextField widthField = new TextField("1920");
widthField.textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
if (!newValue.matches("\\d*")) {
widthField.setText(newValue.replaceAll("[^\\d]", ""));
}
}
});
TextField heightField = new TextField("1080");
heightField.textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
if (!newValue.matches("\\d*")) {
heightField.setText(newValue.replaceAll("[^\\d]", ""));
}
}
});
grid.add(new Label("Width:"), 0, 0);
grid.add(widthField, 1, 0);
grid.add(new Label("Height:"), 0, 1);
grid.add(heightField, 1, 1);
dialog2.getDialogPane().setContent(grid);
dialog2.setResultConverter(dialogButton -> {
if (dialogButton == ButtonType.OK)
return new Pair<String, String>(widthField.getText(), heightField.getText());
return null;
});
Optional<Pair<String, String>> result = dialog2.showAndWait();
int width = 0;
int height = 0;
try {
width = Integer.valueOf(result.get().getKey());
height = Integer.valueOf(result.get().getValue());
} catch (NumberFormatException e) {
AlertMenu aMenu = new AlertMenu("INVALID INPUT: Must be an integer.", "Please try again");
return displayDialog2();
} catch (Exception e) {
e.printStackTrace();
return null;
}
return new Pair<Integer, Integer>(width, height);
}
use of javafx.scene.control.TextField in project DistributedFractalNetwork by Budder21.
the class NetworkCreationTool method getParams.
private Pair<Double, Double> getParams() {
Dialog<Pair<String, String>> dialog3 = new Dialog<>();
dialog3.setTitle("Create Network");
dialog3.setHeaderText("Step 3");
dialog3.setContentText("Choose Parameters:");
dialog3.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
GridPane grid = new GridPane();
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(20, 150, 10, 10));
TextField zoomField = new TextField(".25");
TextField zoomSpeedField = new TextField("1.05");
grid.add(new Label("Zoom Level:"), 0, 0);
grid.add(zoomField, 1, 0);
grid.add(new Label("Zoom Speed:"), 0, 1);
grid.add(zoomSpeedField, 1, 1);
dialog3.getDialogPane().setContent(grid);
dialog3.setResultConverter(dialogButton -> {
if (dialogButton == ButtonType.OK)
return new Pair<String, String>(zoomField.getText(), zoomSpeedField.getText());
return null;
});
Optional<Pair<String, String>> result = dialog3.showAndWait();
// Traditional way to get the response value.
Double speed = null;
try {
speed = Double.valueOf(result.get().getValue());
} catch (NumberFormatException e) {
AlertMenu aMenu = new AlertMenu("INVALID INPUT: Zoom speed must be a real number.", "Please try again.");
return getParams();
} catch (Exception e) {
return null;
}
if (speed <= 0) {
AlertMenu aMenu = new AlertMenu("INVALID INPUT: Zoom speed must be greater than 0.", "Please try again");
return getParams();
}
Double zoom = null;
try {
zoom = Double.valueOf(result.get().getKey());
} catch (NumberFormatException e) {
AlertMenu aMenu = new AlertMenu("INVALID INPUT: Zoom level must be a real number.", "Please try again.");
return getParams();
} catch (Exception e) {
return null;
}
if (zoom <= 0) {
AlertMenu aMenu = new AlertMenu("INVALID INPUT: Zoom level must be greater than 0.", "Please try again");
return getParams();
}
return new Pair<Double, Double>(zoom, speed);
}
use of javafx.scene.control.TextField in project Money-Manager by krHasan.
the class MakeATransactionController method exbtnAdvancedSaveAndAdd.
@FXML
private void exbtnAdvancedSaveAndAdd(ActionEvent event) {
if (total == 0) {
exlblAdvWarningMsg.setText("Empty or Zero is not approved.");
} else {
TextField[] AdvancedExtxt = { extxtAdvSector1, extxtAdvSector2, extxtAdvSector3, extxtAdvSector4, extxtAdvSector5, extxtAdvSector6, extxtAdvSector7 };
Label[] AdvancedExlbl = { exlblAdvSector1, exlblAdvSector2, exlblAdvSector3, exlblAdvSector4, exlblAdvSector5, exlblAdvSector6, exlblAdvSector7 };
int index = 0;
for (TextField textField : AdvancedExtxt) {
if ((!textField.getText().isEmpty()) && (!textField.getText().equals("0"))) {
exAdvSaveFunction(textField.getText(), AdvancedExlbl[index].getText());
}
++index;
}
exInitialize();
extxtAdvancedDescription.clear();
Alert confirmationMsg = new Alert(AlertType.INFORMATION);
confirmationMsg.setTitle("Successfull Transaction");
confirmationMsg.setHeaderText(null);
confirmationMsg.setContentText("Your transaction completed successfully.");
Stage MakeATransactionStage = (Stage) exbtnSave.getScene().getWindow();
confirmationMsg.setX(MakeATransactionStage.getX() + 200);
confirmationMsg.setY(MakeATransactionStage.getY() + 29);
Timeline idlestage = new Timeline(new KeyFrame(Duration.seconds(2), new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
confirmationMsg.hide();
}
}));
idlestage.setCycleCount(1);
idlestage.play();
confirmationMsg.showAndWait();
}
}
Aggregations