use of javafx.event.ActionEvent in project Media-Library by The-Rain-Goddess.
the class ApplicationWindow method getWindowComponents.
private List<Control> getWindowComponents(Stage parent) {
final FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Media Selection.");
//Defining path text field
final TextField songPath = new TextField();
songPath.setPromptText("C:\\... *");
songPath.setPrefColumnCount(30);
songPath.setEditable(false);
songPath.setFocusTraversable(false);
GridPane.setConstraints(songPath, 1, 0);
final Label songPathLabel = new Label("Path: ");
GridPane.setConstraints(songPathLabel, 0, 0);
//Defining the Name text field
final TextField songName = new TextField();
songName.setPromptText("Enter the song's name. *");
songName.setPrefColumnCount(20);
GridPane.setConstraints(songName, 1, 2);
final Label songNameLabel = new Label("Name: ");
GridPane.setConstraints(songNameLabel, 0, 2);
//Defining the Last Name text field
final TextField artistNames = new TextField();
artistNames.setPromptText("Enter the artist name(s). *");
GridPane.setConstraints(artistNames, 1, 3);
final Label songArtistLabel = new Label("Artist(s): ");
GridPane.setConstraints(songArtistLabel, 0, 3);
//Defining the Comment text field
final TextField albumName = new TextField();
albumName.setPrefColumnCount(15);
albumName.setPromptText("Enter the album name. *");
GridPane.setConstraints(albumName, 1, 4);
final Label songAlbumLabel = new Label("Album: ");
GridPane.setConstraints(songAlbumLabel, 0, 4);
//album number
final TextField albumNumber = new TextField();
albumNumber.setPrefColumnCount(20);
albumNumber.setPromptText("Enter the song's album number.");
albumNumber.textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
if (!newValue.matches("\\d*")) {
albumNumber.setText(newValue.replaceAll("[^\\d]", ""));
}
}
});
GridPane.setConstraints(albumNumber, 1, 5);
final Label songNumberLabel = new Label("Number: ");
GridPane.setConstraints(songNumberLabel, 0, 5);
//genre
final TextField genre = new TextField();
genre.setPrefColumnCount(20);
genre.setPromptText("Enter the song's genre.");
GridPane.setConstraints(genre, 1, 6);
final Label songGenreLabel = new Label("Genre: ");
GridPane.setConstraints(songGenreLabel, 0, 6);
//required label
final Label requiredLabel = new Label("* Required");
GridPane.setConstraints(requiredLabel, 1, 7);
//Defining the Submit button
Button submit = new Button("Submit");
GridPane.setConstraints(submit, 2, 3);
submit.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent t) {
if (songName.textProperty() != null && albumName.textProperty() != null && artistNames.textProperty() != null && !songName.textProperty().getValue().equals("") && !albumName.textProperty().getValue().equals("") && !artistNames.textProperty().getValue().equals("") && !songPath.textProperty().getValue().equals("") && songPath.textProperty() != null) {
MediaFile newFile = new MediaFile();
String number = (albumNumber.textProperty().getValue().equals("")) ? "0" : albumNumber.textProperty().getValue();
MediaFileAttribute mfa = new MediaFileAttribute().setAlbum(albumName.textProperty()).setName(songName.textProperty()).setArtists(artistNames.textProperty()).setGenre(genre.textProperty()).setDateCreated(new Date().toString()).setNumber(Integer.parseInt(number)).setPath(songPath.textProperty().getValue()).setPlays(0);
try {
mfa.setLength(AudioFileIO.read(new File(songPath.textProperty().getValue())).getAudioHeader().getTrackLength());
} catch (IOException | NumberFormatException | CannotReadException | TagException | ReadOnlyFileException | InvalidAudioFrameException e) {
e.printStackTrace();
mfa.setLength(Double.NaN);
}
newFile = new MediaFile(mfa, Main.getNextUUID());
System.out.println("Successfuly Added:");
System.out.println(newFile);
String[] attrs = newFile.getFilePath().split("\\.");
newFile.setLibraryFilePath("C:\\Music\\" + newFile.getArtistName() + "\\" + newFile.getAlbumName() + "\\" + newFile.getSongName() + "." + attrs[attrs.length - 1]);
try {
newFile.writeToDisk();
Files.copy(Paths.get(songPath.textProperty().getValue()), Paths.get(newFile.getLibraryFilePath()), StandardCopyOption.COPY_ATTRIBUTES);
} catch (IOException e) {
e.printStackTrace();
}
Main.getMasterData().put(newFile.getUUID(), newFile);
((Stage) ((Button) t.getSource()).getScene().getWindow()).close();
updateDataTable();
updateFileSystem();
}
}
});
//Defining the Clear button
Button clear = new Button("Clear");
clear.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent t) {
List<TextField> fields = Arrays.asList(songPath, songName, artistNames, albumName, albumNumber, genre);
for (TextField s : fields) s.textProperty().set("");
}
});
GridPane.setConstraints(clear, 2, 4);
//Open file button
final Button openFile = new Button("Add media files...");
openFile.setOnAction(new EventHandler<ActionEvent>() {
final TextField path = songPath;
@Override
public void handle(final ActionEvent e) {
List<File> list = fileChooser.showOpenMultipleDialog(parent);
if (list != null) {
for (File file : list) {
path.appendText(file.getAbsolutePath().toString());
}
}
}
});
GridPane.setConstraints(openFile, 2, 0);
return Arrays.asList(songPathLabel, songNameLabel, songArtistLabel, songAlbumLabel, songNumberLabel, songGenreLabel, requiredLabel, songPath, songName, artistNames, albumName, albumNumber, genre, openFile, submit, clear);
}
use of javafx.event.ActionEvent in project SmartCity-Market by TechnionYP5777.
the class DialogMessagesService method showConfirmationDialog.
public static void showConfirmationDialog(String title, String header, String content, IConfiramtionDialog d) {
JFXDialogLayout dialogContent = new JFXDialogLayout();
dialogContent.setHeading(new Text(header == null ? title : title + "\n" + header));
dialogContent.setBody(new Text(content));
JFXButton yes = new JFXButton("Yes");
yes.getStyleClass().add("JFXButton");
JFXButton no = new JFXButton("No");
no.getStyleClass().add("JFXButton");
dialogContent.setActions(yes, new Label(" "), no);
JFXDialog dialog = new JFXDialog((StackPane) AbstractApplicationScreen.stage.getScene().getRoot(), dialogContent, JFXDialog.DialogTransition.CENTER);
yes.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent __) {
dialog.close();
d.onYes();
}
});
no.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent __) {
dialog.close();
d.onNo();
}
});
dialog.show();
}
use of javafx.event.ActionEvent in project Smartcity-Smarthouse by TechnionYP5777.
the class SensorConfigurationController method initialize.
@Override
public void initialize(final URL location, final ResourceBundle __) {
nameColumn.setCellValueFactory(cellData -> new ReadOnlyStringWrapper(cellData.getValue().getName()));
typeColumn.setCellValueFactory(cellData -> new ReadOnlyStringWrapper(cellData.getValue().getType().getFieldDescription()));
deleteColumn.setCellValueFactory(param -> new SimpleBooleanProperty(param.getValue() != null));
deleteColumn.setCellFactory(p -> {
final ButtonCell $ = new ButtonCell();
$.setAlignment(Pos.CENTER);
return $;
});
backButton.setOnAction(__1 -> mainController.loadSensorList());
HBox.setHgrow(addNameField, Priority.ALWAYS);
HBox.setHgrow(addTypeField, Priority.ALWAYS);
HBox.setHgrow(saveButton, Priority.ALWAYS);
addTypeField.setPromptText("Sensor Type");
addTypeField.getItems().addAll(Types.values());
final int btnCount = buttonBox.getChildren().size();
addNameField.prefWidthProperty().bind(buttonBox.widthProperty().divide(btnCount));
addTypeField.prefWidthProperty().bind(buttonBox.widthProperty().divide(btnCount));
saveButton.prefWidthProperty().bind(buttonBox.widthProperty().divide(btnCount));
saveButton.setOnAction(__1 -> addField());
deleteButton.setOnAction(__1 -> {
mainController.removeSensor(currentSensor);
mainController.loadSensorList();
});
messageButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(final ActionEvent __1) {
try {
final FXMLLoader fxmlLoader = new FXMLLoader(this.getClass().getResource("message_ui.fxml"));
final Parent root1 = (Parent) fxmlLoader.load();
((MessageViewController) fxmlLoader.getController()).setCurrentSensor(currentSensor);
final Stage stage = new Stage();
stage.setScene(new Scene(root1));
stage.show();
} catch (final Exception $) {
System.out.println($);
}
}
});
}
use of javafx.event.ActionEvent in project bitsquare by bitsquare.
the class CandleStickChart method dataItemRemoved.
@Override
protected void dataItemRemoved(XYChart.Data<Number, Number> item, XYChart.Series<Number, Number> series) {
if (series.getNode() instanceof Path) {
Path seriesPath = (Path) series.getNode();
seriesPath.getElements().clear();
}
final Node node = item.getNode();
if (shouldAnimate()) {
// fade out old candle
FadeTransition ft = new FadeTransition(Duration.millis(500), node);
ft.setToValue(0);
ft.setOnFinished((ActionEvent actionEvent) -> {
getPlotChildren().remove(node);
});
ft.play();
} else {
getPlotChildren().remove(node);
}
}
use of javafx.event.ActionEvent in project bitsquare by bitsquare.
the class VolumeChart method dataItemRemoved.
@Override
protected void dataItemRemoved(XYChart.Data<Number, Number> item, XYChart.Series<Number, Number> series) {
final Node node = item.getNode();
if (shouldAnimate()) {
FadeTransition ft = new FadeTransition(Duration.millis(500), node);
ft.setToValue(0);
ft.setOnFinished((ActionEvent actionEvent) -> getPlotChildren().remove(node));
ft.play();
} else {
getPlotChildren().remove(node);
}
}
Aggregations