Search in sources :

Example 1 with ActionEvent

use of javafx.event.ActionEvent in project SmartCity-Market by TechnionYP5777.

the class DialogMessagesService method alertCreator.

private static void alertCreator(String title, String header, String content) {
    JFXDialogLayout dialogContent = new JFXDialogLayout();
    dialogContent.setHeading(new Text(header == null ? title : title + "\n" + header));
    dialogContent.setBody(new Text(content));
    JFXButton close = new JFXButton("Close");
    close.getStyleClass().add("JFXButton");
    dialogContent.setActions(close);
    JFXDialog dialog = new JFXDialog((StackPane) AbstractApplicationScreen.stage.getScene().getRoot(), dialogContent, JFXDialog.DialogTransition.CENTER);
    close.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent __) {
            dialog.close();
        }
    });
    dialog.show();
}
Also used : ActionEvent(javafx.event.ActionEvent) JFXDialog(com.jfoenix.controls.JFXDialog) Text(javafx.scene.text.Text) JFXButton(com.jfoenix.controls.JFXButton) JFXDialogLayout(com.jfoenix.controls.JFXDialogLayout)

Example 2 with ActionEvent

use of javafx.event.ActionEvent in project SmartCity-Market by TechnionYP5777.

the class ManageCatalogProductDetailsTab method initialize.

@Override
public void initialize(URL location, ResourceBundle __) {
    createManufacturerList();
    createIngredientList();
    filterManu.textProperty().addListener(obs -> {
        String filter = filterManu.getText();
        filteredDataManu.setPredicate(filter == null || filter.length() == 0 ? s -> true : s -> s.contains(filter));
    });
    manufacturerList.setCellFactory(CheckBoxListCell.forListView(new Callback<String, ObservableValue<Boolean>>() {

        @Override
        public ObservableValue<Boolean> call(String item) {
            BooleanProperty observable = new SimpleBooleanProperty();
            observable.set(selectedManu.contains(item));
            observable.addListener((obs, wasSelected, isNowSelected) -> {
                if (isNowSelected)
                    selectedManu.add(item);
                else
                    selectedManu.remove(item);
                enableButtons();
            });
            return observable;
        }
    }));
    filterIngr.textProperty().addListener(obs -> {
        String filter = filterIngr.getText();
        filteredDataIngr.setPredicate(filter == null || filter.length() == 0 ? s -> true : s -> s.contains(filter));
    });
    ingredientsList.setCellFactory(CheckBoxListCell.forListView(new Callback<String, ObservableValue<Boolean>>() {

        @Override
        public ObservableValue<Boolean> call(String item) {
            BooleanProperty observable = new SimpleBooleanProperty();
            observable.set(selectedIngr.contains(item));
            observable.addListener((obs, wasSelected, isNowSelected) -> {
                if (isNowSelected)
                    selectedIngr.add(item);
                else
                    selectedIngr.remove(item);
                enableButtons();
            });
            return observable;
        }
    }));
    Label lbl1 = new Label("Insert New Manufacturar");
    newManu = new JFXTextField();
    okNewManu = new JFXButton("Done!");
    okNewManu.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent __) {
            addManuPressed();
        }
    });
    VBox manuContainer = new VBox();
    manuContainer.getChildren().addAll(lbl1, newManu, okNewManu);
    manuContainer.setPadding(new Insets(10, 50, 50, 50));
    manuContainer.setSpacing(10);
    JFXPopup popup1 = new JFXPopup(manuContainer);
    addManuBtn.setOnMouseClicked(e -> popup1.show(addManuBtn, PopupVPosition.TOP, PopupHPosition.LEFT));
    newManu.textProperty().addListener((observable, oldValue, newValue) -> enableAddButtons());
    Label lbl2 = new Label("Insert New Ingredient");
    newIngr = new JFXTextField();
    okNewIngr = new JFXButton("Done!");
    okNewIngr.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent __) {
            addIngPressed();
        }
    });
    VBox ingrContainer = new VBox();
    ingrContainer.getChildren().addAll(lbl2, newIngr, okNewIngr);
    ingrContainer.setPadding(new Insets(10, 50, 50, 50));
    ingrContainer.setSpacing(10);
    JFXPopup popup2 = new JFXPopup(ingrContainer);
    addIngrBtn.setOnMouseClicked(e -> popup2.show(addIngrBtn, PopupVPosition.TOP, PopupHPosition.LEFT));
    newIngr.textProperty().addListener((observable, oldValue, newValue) -> enableAddButtons());
    Label lbl3 = new Label("Rename Selected Manufacturar");
    renameManuLbl = new JFXTextField();
    okRenameManu = new JFXButton("Done!");
    okRenameManu.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent __) {
            renameManuPressed();
        }
    });
    VBox renameManuContainer = new VBox();
    renameManuContainer.getChildren().addAll(lbl3, renameManuLbl, okRenameManu);
    renameManuContainer.setPadding(new Insets(10, 50, 50, 50));
    renameManuContainer.setSpacing(10);
    JFXPopup popup3 = new JFXPopup(renameManuContainer);
    renameManu.setOnMouseClicked(e -> popup3.show(renameManu, PopupVPosition.TOP, PopupHPosition.LEFT));
    renameManuLbl.textProperty().addListener((observable, oldValue, newValue) -> enableAddButtons());
    Label lbl4 = new Label("Rename Selected Ingredient");
    renameIngrLbl = new JFXTextField();
    okRenameIngr = new JFXButton("Done!");
    okRenameIngr.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent __) {
            renameIngrPressed();
        }
    });
    VBox renameIngrContainer = new VBox();
    renameIngrContainer.getChildren().addAll(lbl4, renameIngrLbl, okRenameIngr);
    renameIngrContainer.setPadding(new Insets(10, 50, 50, 50));
    renameIngrContainer.setSpacing(10);
    JFXPopup popup4 = new JFXPopup(renameIngrContainer);
    renameIngr.setOnMouseClicked(e -> popup4.show(renameIngr, PopupVPosition.TOP, PopupHPosition.LEFT));
    renameIngrLbl.textProperty().addListener((observable, oldValue, newValue) -> enableAddButtons());
    enableButtons();
    enableAddButtons();
}
Also used : EventHandler(javafx.event.EventHandler) JFXButton(com.jfoenix.controls.JFXButton) Initializable(javafx.fxml.Initializable) URL(java.net.URL) CheckBoxListCell(javafx.scene.control.cell.CheckBoxListCell) PopupVPosition(com.jfoenix.controls.JFXPopup.PopupVPosition) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) Manufacturer(BasicCommonClasses.Manufacturer) VBox(javafx.scene.layout.VBox) JFXPopup(com.jfoenix.controls.JFXPopup) EmployeeNotConnected(EmployeeDefs.AEmployeeException.EmployeeNotConnected) HashSet(java.util.HashSet) ParamIDAlreadyExists(EmployeeDefs.AEmployeeException.ParamIDAlreadyExists) Logger(org.apache.log4j.Logger) Insets(javafx.geometry.Insets) ResourceBundle(java.util.ResourceBundle) ManfacturerStillInUse(EmployeeDefs.AEmployeeException.ManfacturerStillInUse) ConnectionFailure(EmployeeDefs.AEmployeeException.ConnectionFailure) ParamIDDoesNotExist(EmployeeDefs.AEmployeeException.ParamIDDoesNotExist) Callback(javafx.util.Callback) CriticalError(SMExceptions.CommonExceptions.CriticalError) Label(javafx.scene.control.Label) StackTraceUtil(UtilsImplementations.StackTraceUtil) JFXListView(com.jfoenix.controls.JFXListView) FilteredList(javafx.collections.transformation.FilteredList) Manager(EmployeeImplementations.Manager) IngredientStillInUse(EmployeeDefs.AEmployeeException.IngredientStillInUse) FXML(javafx.fxml.FXML) InjectionFactory(UtilsImplementations.InjectionFactory) BooleanProperty(javafx.beans.property.BooleanProperty) ActionEvent(javafx.event.ActionEvent) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) PopupHPosition(com.jfoenix.controls.JFXPopup.PopupHPosition) IManager(EmployeeContracts.IManager) ObservableValue(javafx.beans.value.ObservableValue) ObservableList(javafx.collections.ObservableList) Ingredient(BasicCommonClasses.Ingredient) JFXTextField(com.jfoenix.controls.JFXTextField) InvalidParameter(EmployeeDefs.AEmployeeException.InvalidParameter) JFXPopup(com.jfoenix.controls.JFXPopup) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) Insets(javafx.geometry.Insets) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) ActionEvent(javafx.event.ActionEvent) JFXTextField(com.jfoenix.controls.JFXTextField) Label(javafx.scene.control.Label) JFXButton(com.jfoenix.controls.JFXButton) Callback(javafx.util.Callback) VBox(javafx.scene.layout.VBox)

Example 3 with ActionEvent

use of javafx.event.ActionEvent in project Smartcity-Smarthouse by TechnionYP5777.

the class ConfigController method subscribe.

public void subscribe(final StoveAppController mainController) {
    HBox.setHgrow(Apply, Priority.ALWAYS);
    HBox.setHgrow(Cancel, Priority.ALWAYS);
    final int btnCount = ButtonBox.getChildren().size();
    Apply.prefWidthProperty().bind(ButtonBox.widthProperty().divide(btnCount));
    Cancel.prefWidthProperty().bind(ButtonBox.widthProperty().divide(btnCount));
    Cancel.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(final ActionEvent __1) {
            // do what you have to do
            ((Stage) Cancel.getScene().getWindow()).close();
        }
    });
    Apply.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(final ActionEvent __1) {
            final Stage stage = (Stage) Apply.getScene().getWindow();
            final String time = secs.getText(), degrees = cels.getText();
            if (validateInput(time, degrees)) {
                mainController.set_alert_seconds(Integer.parseInt(secs.getText()));
                mainController.set_alert_temperature(Integer.parseInt(cels.getText()));
                stage.close();
            } else {
                final Alert alert = new Alert(AlertType.ERROR);
                alert.setTitle("Error Dialog");
                alert.setHeaderText("Bad Input");
                alert.setContentText("Make sure to enter only numbers");
                alert.showAndWait();
            }
        }
    });
}
Also used : ActionEvent(javafx.event.ActionEvent) Stage(javafx.stage.Stage) Alert(javafx.scene.control.Alert)

Example 4 with ActionEvent

use of javafx.event.ActionEvent in project POL-POM-5 by PlayOnLinux.

the class RepositoriesPanel method populateRepositoryGrid.

private void populateRepositoryGrid() {
    this.title = new TextWithStyle(tr("Repositories Settings"), "title");
    this.repositoryGrid = new GridPane();
    this.repositoryGrid.getStyleClass().add("grid");
    this.repositoryText = new TextWithStyle(tr("Repository:"), "captionTitle");
    this.repositoryLayout = new VBox();
    this.repositoryLayout.setSpacing(5);
    this.repositoryListView = new ListView<>(repositories);
    this.repositoryListView.setPrefHeight(0);
    this.repositoryListView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    this.repositoryListView.setEditable(true);
    this.repositoryListView.setCellFactory(param -> new DragableRepositoryListCell((repositoryUrl, toIndex) -> {
        this.repositoryManager.moveRepository(repositoryUrl, toIndex.intValue());
        this.save();
    }));
    this.repositoryButtonLayout = new HBox();
    this.repositoryButtonLayout.setSpacing(5);
    this.addButton = new Button();
    this.addButton.setText(tr("Add"));
    this.addButton.setOnAction((ActionEvent event) -> {
        TextInputDialog dialog = new TextInputDialog();
        dialog.initOwner(getScene().getWindow());
        dialog.setTitle(tr("Add repository"));
        dialog.setHeaderText(tr("Add repository"));
        dialog.setContentText(tr("Please add the new repository:"));
        Optional<String> result = dialog.showAndWait();
        result.ifPresent(newRepository -> {
            repositories.add(0, newRepository);
            this.save();
            repositoryManager.addRepositories(0, newRepository);
        });
    });
    this.removeButton = new Button();
    this.removeButton.setText(tr("Remove"));
    this.removeButton.setOnAction((ActionEvent event) -> {
        String[] toRemove = repositoryListView.getSelectionModel().getSelectedItems().toArray(new String[0]);
        repositories.removeAll(toRemove);
        this.save();
        repositoryManager.removeRepositories(toRemove);
    });
    this.repositoryButtonLayout.getChildren().addAll(addButton, removeButton);
    this.repositoryLayout.getChildren().addAll(repositoryListView, repositoryButtonLayout);
    VBox.setVgrow(repositoryListView, Priority.ALWAYS);
    this.repositoryGrid.add(repositoryText, 0, 0);
    this.repositoryGrid.add(repositoryLayout, 1, 0);
    GridPane.setHgrow(repositoryLayout, Priority.ALWAYS);
    GridPane.setVgrow(repositoryLayout, Priority.ALWAYS);
    GridPane.setValignment(repositoryText, VPos.TOP);
}
Also used : Pos(javafx.geometry.Pos) javafx.scene.layout(javafx.scene.layout) javafx.scene.control(javafx.scene.control) RepositoryManager(org.phoenicis.repository.RepositoryManager) TextWithStyle(org.phoenicis.javafx.views.common.TextWithStyle) FXCollections(javafx.collections.FXCollections) Localisation.tr(org.phoenicis.configuration.localisation.Localisation.tr) Platform(javafx.application.Platform) Text(javafx.scene.text.Text) ActionEvent(javafx.event.ActionEvent) Insets(javafx.geometry.Insets) SettingsManager(org.phoenicis.settings.SettingsManager) VPos(javafx.geometry.VPos) Optional(java.util.Optional) ObservableList(javafx.collections.ObservableList) TextWithStyle(org.phoenicis.javafx.views.common.TextWithStyle) ActionEvent(javafx.event.ActionEvent)

Example 5 with ActionEvent

use of javafx.event.ActionEvent in project TeachingInSimulation by ScOrPiOzzy.

the class ExamController method initialize.

public void initialize(LibraryPublish publish) {
    clear();
    this.publish = publish;
    this.library = publish.getLibrary();
    this.libraryName.setTitle(library.getName());
    // 创建答题卡项
    List<Question> questions = this.library.getQuestions();
    // // XXX 暂时不做:顺序打乱
    // Collections.shuffle(questions);
    float total = 0f;
    for (int i = 0; i < questions.size(); i++) {
        ToggleButton toggle = new ToggleButton(String.valueOf(i + 1));
        toggle.getStyleClass().add("undo");
        toggle.setUserData(i);
        toggle.setWrapText(false);
        flow.getChildren().add(toggle);
        group.getToggles().add(toggle);
        Question question = questions.get(i);
        LibraryAnswer libraryAnswer = new LibraryAnswer();
        libraryAnswer.setIndex(i);
        libraryAnswer.setQuestion(question);
        libraryAnswer.setQuestionId(question.getId());
        this.answers.put(i, libraryAnswer);
        total += question.getPoint();
    }
    this.total.setText(String.valueOf(total));
    groupListener = (b, o, n) -> {
        if (o == null) {
            return;
        } else if (n == null) {
            this.group.selectToggle(o);
            return;
        }
        if (!submited) {
            // 验证上一个试题是否作答完成
            checkAnswer((ToggleButton) o);
        }
        // 加载下一个试题
        currIndex = (int) n.getUserData();
        prev.setDisable(false);
        next.setDisable(false);
        if (currIndex <= 0) {
            prev.setDisable(true);
        }
        if (currIndex >= questions.size() - 1) {
            next.setDisable(true);
        }
        loadQuestion();
    };
    group.selectedToggleProperty().addListener(groupListener);
    group.selectToggle(group.getToggles().get(0));
    loadQuestion();
    // 启动计时器
    timeline = new Timeline();
    timeline.setCycleCount(Timeline.INDEFINITE);
    timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(1), (ActionEvent event1) -> {
        cost++;
        this.minute.setText(String.valueOf(cost / 60));
        this.second.setText(String.valueOf(cost % 60));
    }));
    timeline.play();
}
Also used : LibraryAnswer(com.cas.sim.tis.entity.LibraryAnswer) ToggleButton(javafx.scene.control.ToggleButton) Timeline(javafx.animation.Timeline) ActionEvent(javafx.event.ActionEvent) KeyFrame(javafx.animation.KeyFrame) Question(com.cas.sim.tis.entity.Question)

Aggregations

ActionEvent (javafx.event.ActionEvent)171 EventHandler (javafx.event.EventHandler)61 Stage (javafx.stage.Stage)52 KeyFrame (javafx.animation.KeyFrame)47 Timeline (javafx.animation.Timeline)47 FXML (javafx.fxml.FXML)44 Alert (javafx.scene.control.Alert)36 Button (javafx.scene.control.Button)35 Label (javafx.scene.control.Label)35 MenuItem (javafx.scene.control.MenuItem)33 ContextMenu (javafx.scene.control.ContextMenu)25 File (java.io.File)24 Insets (javafx.geometry.Insets)24 Scene (javafx.scene.Scene)24 List (java.util.List)21 ObservableList (javafx.collections.ObservableList)21 Node (javafx.scene.Node)20 TextField (javafx.scene.control.TextField)20 Optional (java.util.Optional)18 FXCollections (javafx.collections.FXCollections)18