Example usage for javafx.beans.value ChangeListener ChangeListener

List of usage examples for javafx.beans.value ChangeListener ChangeListener

Introduction

In this page you can find the example usage for javafx.beans.value ChangeListener ChangeListener.

Prototype

ChangeListener

Source Link

Usage

From source file:de.hs.mannheim.modUro.controller.diagram.SimulationDiagramController.java

public void init(Simulation simulation) {
    this.simulation = simulation;
    this.simulationDiagram = new SimulationDiagram(simulation);

    if (leftLastSelectedIndex == null || rightLastSelectedIndex == null) {
        initializeChoiceboxContent();// w  w w . j  a  v a 2s .  c  o m
    } else {
        if (simulationContainsMetricType()) {
            setChoiceBoxContent();
            setLeftChartContent(leftLastSelectedIndex);
            setRightChartContent(rightLastSelectedIndex);
        } else {
            Alert alert = new Alert(Alert.AlertType.WARNING);
            alert.setTitle("Warning");
            alert.setHeaderText("Metrictype Warning");
            alert.setContentText("Simulation does not have Metrictype: " + leftLastSelectedMetrictypename);
            alert.showAndWait();

            initializeChoiceboxContent();
        }

    }

    /*ChangeListerners for selected items in choicebox.*/
    leftMetricType.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
        @Override
        public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
            setLeftChartContent(newValue.intValue());
            leftLastSelectedIndex = newValue.intValue();
            leftLastSelectedMetrictypename = choiceBoxMetrictypeNames().get(leftLastSelectedIndex);

        }
    });

    rightMetricType.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
        @Override
        public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
            setRightChartContent(newValue.intValue());
            rightLastSelectedIndex = newValue.intValue();
            rightLastSelectedMetrictypename = choiceBoxMetrictypeNames().get(rightLastSelectedIndex);
        }
    });
}

From source file:org.opendolphin.mvndemo.clientlazy.DemoController.java

@Override
public void initialize(URL url, ResourceBundle rb) {
    //Sending Command and get list with column names in the response.
    DemoApp.clientDolphin.send(CMD_GETLAZYCOLUMNS, new OnFinishedHandlerAdapter() {
        @Override//from  w  w  w .  j  a  v  a  2s.c om
        public void onFinishedData(List<Map> data) {
            if (data != null && data.size() == 1) {
                //Create lazy table with colums from the response
                createTableLazy(data);
            }
        }

    });
    //
    // when starting, first fill the table with pm ids
    DemoApp.clientDolphin.send(CMD_LAZYTABLELOAD, new OnFinishedHandlerAdapter() {
        @Override
        public void onFinishedData(List<Map> data) {
            for (Map map : data) {
                lazyRows.addAll(map.values());
            }
            unused.setValue(lazyRows.size());
        }
    });
    //
    ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList();
    PieChart.Data usedData = new PieChart.Data("Used", 23);
    usedData.pieValueProperty().bind(used);
    pieChartData.add(usedData);
    PieChart.Data unusedData = new PieChart.Data("unused", 100 - 23);
    unusedData.pieValueProperty().bind(unused);
    pieChartData.add(unusedData);
    pieLazyUse.setData(pieChartData);
    //
    used.addListener(new ChangeListener<Number>() {

        @Override
        public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
            pieLabel.setText(String.format("Zeilen: %d / %d ", newValue, lazyRows.size()));
        }
    });
    //
    DemoApp.clientDolphin.getClientConnector().setUiThreadHandler(new JavaFXUiThreadHandler());
}

From source file:org.openbase.display.WebTab.java

/**
 * Loads the given HTML content directly. This method is useful when you have an HTML
 * String composed in memory, or loaded from some system which cannot be reached via
 * a URL (for example, the HTML text may have come from a database). As with
 * {@link #load(String)}, this method is asynchronous.
 *
 * @param content/*from w  w  w  .  j  a v  a2s . c  o m*/
 * @throws org.openbase.jul.exception.CouldNotPerformException
 */
public void loadContent(final String content) throws CouldNotPerformException {
    try {
        if (content == null) {
            throw new NotAvailableException("Content");
        }

        if (!content.equals(this.content)) {
            // load new content and display after loading content.
            webView.getEngine().getLoadWorker().stateProperty().addListener(new ChangeListener<Worker.State>() {
                @Override
                public void changed(ObservableValue<? extends Worker.State> observable, Worker.State oldValue,
                        Worker.State newValue) {
                    if (newValue != Worker.State.SUCCEEDED) {
                        return;
                    }
                    displayTab();
                }
            });
            webView.getEngine().loadContent(content);
            this.content = content;
        } else {
            displayTab();
        }

    } catch (CouldNotPerformException ex) {
        throw new CouldNotPerformException("Could not load web content!", ex);
    }
}

From source file:gov.va.isaac.gui.preferences.PreferencesViewController.java

public void aboutToShow() {
    // Using allValid_ to prevent rerunning content of aboutToShow()
    if (allValid_ == null) {
        // These listeners are for debug and testing only. They may be removed at any time.
        UserProfileBindings userProfileBindings = AppContext.getService(UserProfileBindings.class);
        for (Property<?> property : userProfileBindings.getAll()) {
            property.addListener(new ChangeListener<Object>() {
                @Override/*  w  w  w  . j a v a  2  s .c o m*/
                public void changed(ObservableValue<? extends Object> observable, Object oldValue,
                        Object newValue) {
                    logger.debug("{} property changed from {} to {}", property.getName(), oldValue, newValue);
                }
            });
        }

        // load fields before initializing allValid_
        // in case plugin.validationFailureMessageProperty() initialized by getNode()
        tabPane_.getTabs().clear();
        List<PreferencesPluginViewI> sortableList = new ArrayList<>();
        Comparator<PreferencesPluginViewI> comparator = new Comparator<PreferencesPluginViewI>() {
            @Override
            public int compare(PreferencesPluginViewI o1, PreferencesPluginViewI o2) {
                if (o1.getTabOrder() == o2.getTabOrder()) {
                    return o1.getName().compareTo(o2.getName());
                } else {
                    return o1.getTabOrder() - o2.getTabOrder();
                }
            }
        };
        for (PreferencesPluginViewI plugin : plugins_) {
            sortableList.add(plugin);
        }
        Collections.sort(sortableList, comparator);
        for (PreferencesPluginViewI plugin : sortableList) {
            logger.debug("Adding PreferencesPluginView tab \"{}\"", plugin.getName());
            Label tabLabel = new Label(plugin.getName());

            tabLabel.setMaxHeight(Double.MAX_VALUE);
            tabLabel.setMaxWidth(Double.MAX_VALUE);
            Tab pluginTab = new Tab();
            pluginTab.setGraphic(tabLabel);
            Region content = plugin.getContent();
            content.setMaxWidth(Double.MAX_VALUE);
            content.setMaxHeight(Double.MAX_VALUE);
            content.setPadding(new Insets(5.0));

            Label errorMessageLabel = new Label();
            errorMessageLabel.textProperty().bind(plugin.validationFailureMessageProperty());
            errorMessageLabel.setAlignment(Pos.BOTTOM_CENTER);
            TextErrorColorHelper.setTextErrorColor(errorMessageLabel);

            VBox vBox = new VBox();
            vBox.getChildren().addAll(errorMessageLabel, content);
            vBox.setMaxWidth(Double.MAX_VALUE);
            vBox.setAlignment(Pos.TOP_CENTER);

            plugin.validationFailureMessageProperty().addListener(new ChangeListener<String>() {
                @Override
                public void changed(ObservableValue<? extends String> observable, String oldValue,
                        String newValue) {
                    if (newValue != null && !StringUtils.isEmpty(newValue)) {
                        TextErrorColorHelper.setTextErrorColor(tabLabel);
                    } else {
                        TextErrorColorHelper.clearTextErrorColor(tabLabel);
                    }
                }
            });
            //Initialize, if stored value is wrong
            if (StringUtils.isNotEmpty(plugin.validationFailureMessageProperty().getValue())) {
                TextErrorColorHelper.setTextErrorColor(tabLabel);
            }
            pluginTab.setContent(vBox);
            tabPane_.getTabs().add(pluginTab);
        }

        allValid_ = new ValidBooleanBinding() {
            {
                ArrayList<ReadOnlyStringProperty> pluginValidationFailureMessages = new ArrayList<>();
                for (PreferencesPluginViewI plugin : plugins_) {
                    pluginValidationFailureMessages.add(plugin.validationFailureMessageProperty());
                }
                bind(pluginValidationFailureMessages
                        .toArray(new ReadOnlyStringProperty[pluginValidationFailureMessages.size()]));
                setComputeOnInvalidate(true);
            }

            @Override
            protected boolean computeValue() {
                for (PreferencesPluginViewI plugin : plugins_) {
                    if (plugin.validationFailureMessageProperty().get() != null
                            && plugin.validationFailureMessageProperty().get().length() > 0) {
                        this.setInvalidReason(plugin.validationFailureMessageProperty().get());

                        logger.debug("Setting PreferencesView allValid_ to false because \"{}\"",
                                this.getReasonWhyInvalid().get());
                        return false;
                    }
                }

                logger.debug("Setting PreferencesView allValid_ to true");

                this.clearInvalidReason();
                return true;
            }
        };

        okButton_.disableProperty().bind(allValid_.not());
        // set focus on default
        // Platform.runLater(...);
    }

    // Reload persisted values every time view opened
    for (PreferencesPluginViewI plugin : plugins_) {
        plugin.getContent();
    }
}

From source file:pah9qdmoviereviews.MovieReviewsFXMLController.java

public void ready(Stage stage, Scene scene) {
    this.stage = stage;
    this.scene = scene;

    movieReviewManager = new NYTMoviewReviewManager();
    movieReviewManager.addPropertyChangeSupport(((evt) -> {
        switch (evt.getPropertyName()) {
        case "Exception":
            Platform.runLater(() -> displayExceptionAlert((Exception) evt.getNewValue()));
            break;
        case "Add Movie Review":
            Platform.runLater(() -> {
                movieReviews.add((NYTMovieReview) evt.getNewValue());
                this.foundText.setText(("Found " + movieReviews.size() + " results for " + searchString + "."));
            });//from ww w .jav  a 2 s  .c om
            break;
        case "Clear Movie Reviews":
            Platform.runLater(() -> movieReviews.clear());
            break;
        case "Completed":
            if (movieReviews.isEmpty())
                this.foundText.setText("No reviews found for " + searchString);
            break;
        default:
            Platform.runLater(
                    () -> displayExceptionAlert(new Exception("Invalid Property Change Support Property")));
            break;
        }

    }));

    movieReviews = FXCollections.observableArrayList();
    listView.setItems(movieReviews);
    listView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<NYTMovieReview>() {
        @Override
        public void changed(ObservableValue<? extends NYTMovieReview> observable, NYTMovieReview oldValue,
                NYTMovieReview newValue) {
            detailsBox.getChildren().clear();
            movieImage.setImage(null);
            if (newValue != null) {
                DateFormat dateFormat = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH);
                String pictureLink = newValue.getPictureLink();
                if (pictureLink != null && !pictureLink.isEmpty()) {
                    reviewBox.getChildren().remove(0);
                    reviewBox.getChildren().add(0, movieImage);
                    movieImage.setImage(new Image(pictureLink));
                } else {
                    reviewBox.getChildren().remove(0);
                    reviewBox.getChildren().add(0, missingImageText);
                    movieImage.setImage(null);
                }

                ArrayList<Label> labelArray = new ArrayList<>();
                if (!newValue.getDisplayTitle().isEmpty()) {
                    Label titleLabel = new Label(newValue.getDisplayTitle());
                    titleLabel.fontProperty().set(Font.font(20));
                    labelArray.add(titleLabel);
                }
                if (!newValue.getSummary().isEmpty()) {
                    labelArray.add(new Label("Summary: " + newValue.getSummary()));
                }
                if (!newValue.getMpaaRating().isEmpty()) {
                    labelArray.add(new Label("MPAA Rating: " + newValue.getMpaaRating()));
                }
                if (newValue.getPublicationDate() != null) {
                    labelArray.add(
                            new Label("Publication Date: " + dateFormat.format(newValue.getPublicationDate())));
                }
                if (newValue.getOpeningDate() != null) {
                    labelArray.add(new Label("Opening Date: " + dateFormat.format(newValue.getOpeningDate())));
                }

                labelArray.forEach((label) -> {
                    label.wrapTextProperty().set(true);
                });

                detailsBox.getChildren().addAll(labelArray);

                Button openButton = new Button("Open Review");
                openButton.setOnAction((event) -> {
                    try {
                        Desktop.getDesktop().browse(new URI(newValue.getArticleLink()));
                    } catch (Exception ex) {
                        displayExceptionAlert(ex);
                    }
                });

                detailsBox.getChildren().add(openButton);
            }
        }
    });

    HBox.setMargin(missingImageText, new Insets(15, 15, 15, 15));
    searchTextField.setOnKeyPressed((event) -> {
        if (event.getCode() == KeyCode.ENTER) {
            loadReviews(searchTextField.getText());
        }
    });
    //        searchTextField.textProperty().addListener((observable, oldValue, newValue) -> {
    //            if(newValue != null && !newValue.isEmpty())
    //                loadReviews(newValue);
    //        });
}

From source file:Person.java

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("");
    Group root = new Group();
    Scene scene = new Scene(root, 500, 250, Color.WHITE);
    // create a grid pane
    GridPane gridpane = new GridPane();
    gridpane.setPadding(new Insets(5));
    gridpane.setHgap(10);//from w w w.  j ava2 s. co  m
    gridpane.setVgap(10);

    ObservableList<Person> leaders = FXCollections.observableArrayList();
    leaders.add(new Person("A", "B", "C"));
    leaders.add(new Person("D", "E", "F"));
    final ListView<Person> leaderListView = new ListView<Person>(leaders);
    leaderListView.setPrefWidth(150);
    leaderListView.setPrefHeight(150);

    // 
    leaderListView.setCellFactory(new Callback<ListView<Person>, ListCell<Person>>() {

        public ListCell<Person> call(ListView<Person> param) {
            final Label leadLbl = new Label();
            final Tooltip tooltip = new Tooltip();
            final ListCell<Person> cell = new ListCell<Person>() {
                @Override
                public void updateItem(Person item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null) {
                        leadLbl.setText(item.getAliasName());
                        setText(item.getFirstName() + " " + item.getLastName());
                        tooltip.setText(item.getAliasName());
                        setTooltip(tooltip);
                    }
                }
            }; // ListCell
            return cell;
        }
    }); // setCellFactory

    gridpane.add(leaderListView, 0, 1);

    leaderListView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Person>() {
        public void changed(ObservableValue<? extends Person> observable, Person oldValue, Person newValue) {
            System.out.println("selection changed");
        }
    });

    root.getChildren().add(gridpane);

    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:fruitproject.FruitProject.java

public void first(final Stage primaryStage) {
    GridPane grid = new GridPane();
    grid.setAlignment(Pos.CENTER);/* w  w w  .  j  a  v a  2s . c o m*/
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(25, 25, 25, 25));

    rows = 0;
    addPairs.clear();

    Text lb = new Text();
    lb.setText("J-Fruit");
    //lb.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
    grid.add(lb, 1, 0);

    final ToggleGroup grp = new ToggleGroup();
    RadioButton rb1 = new RadioButton();
    rb1.setText("Add Fruit file");
    rb1.setUserData("add");
    rb1.setToggleGroup(grp);
    rb1.setSelected(true);
    grid.add(rb1, 1, 1);

    RadioButton rb2 = new RadioButton();
    rb2.setText("Load Fruit file");
    rb2.setUserData("load");
    rb2.setToggleGroup(grp);
    grid.add(rb2, 1, 2);

    Label label1 = new Label("Enter File Name:");
    final TextField tfFilename = new TextField();
    final HBox hb = new HBox();
    hb.getChildren().addAll(label1, tfFilename);
    hb.setSpacing(10);
    hb.setVisible(false);
    tfFilename.setText("");
    grid.add(hb, 1, 3);

    grp.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
        public void changed(ObservableValue<? extends Toggle> ov, Toggle old_toggle, Toggle new_toggle) {
            if (grp.getSelectedToggle() != null) {
                // System.out.println(grp.getSelectedToggle().getUserData().toString());
                if (grp.getSelectedToggle().getUserData().toString() == "load")
                    hb.setVisible(true);
                else {
                    hb.setVisible(false);
                    tfFilename.setText("");
                }
            }
        }
    });

    if (rb2.isSelected() == true) {
        hb.setVisible(true);
    }

    Button btn = new Button();
    btn.setText("GO");
    grid.add(btn, 1, 4);
    btn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            //System.out.println("Hello World!");
            if (tfFilename.getText() == "")
                second("");
            else
                second(tfFilename.getText());
            primaryStage.close();
        }
    });

    //StackPane root = new StackPane();
    //root.getChildren().add(lb);
    //root.getChildren().add(rb1);
    //root.getChildren().add(rb2);
    //root.getChildren().add(btn);

    Scene scene = new Scene(grid, 400, 450);
    primaryStage.setTitle("Hello World!");
    primaryStage.setScene(scene);
    primaryStage.show();

}

From source file:com.panemu.tiwulfx.form.Form.java

private void scanInputControls(Node node) {
    Pane parent = null;/*  www .  j av  a2 s. c o  m*/
    if (node instanceof Pane) {
        parent = (Pane) node;
    } else if (node instanceof TitledPane) {
        scanInputControls(((TitledPane) node).getContent());
        return;
    } else if (node instanceof ScrollPane) {
        scanInputControls(((ScrollPane) node).getContent());
        return;
    }
    if (parent == null) {
        return;
    }
    for (final Node component : parent.getChildren()) {
        if (!(component instanceof BaseControl)) {
            scanInputControls(component);
        } else if (component instanceof BaseControl) {
            BaseControl baseControl = (BaseControl) component;
            lstInputControl.add(baseControl);
            mapEditable.put(baseControl, baseControl.isEditable());
            baseControl.editableProperty().addListener(new EditableController(baseControl));
            if (component instanceof LookupControl) {
                ((BaseControl) component).valueProperty().addListener(new ChangeListener() {
                    @Override
                    public void changed(ObservableValue ov, Object t, Object t1) {
                        updateNestedObject(((BaseControl) component).getPropertyName(), t1);
                    }
                });
            }
        }
    }
}

From source file:org.sandsoft.acefx.AceEditor.java

/**
 * Initializes view and controls after FXML is loaded.
 *//*  ww  w. j a  v a2  s.com*/
public void initialize() {
    //setup view   
    webView.setContextMenuEnabled(false);
    mWebEngine = webView.getEngine();
    loadAceEditor();
    loadModeList();
    loadThemeList();

    // process page loading
    mWebEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<Worker.State>() {
        @Override
        public void changed(ObservableValue<? extends Worker.State> ov, Worker.State t, Worker.State t1) {
            if (mWebEngine.getLoadWorker().getState() == Worker.State.SUCCEEDED) {
                //extract javascript objects
                mAce = (JSObject) mWebEngine.executeScript("ace");
                JSObject editor = (JSObject) mAce.call("edit", "editor");
                mEditor = new Editor(editor);

                setEventCatchers(editor);
                setTheme(Themes.Chrome);
                setMode(Modes.Text);

                fireEvent(new Event(AceEvents.onLoadEvent));
            }
        }
    });
}

From source file:caillou.company.clonemanager.gui.customComponent.excludeTree.ExcludeTreeController.java

public void buildTreeLazily(final CheckBoxTreeItem<DirectoryLazyCheckableTreeItem> currentItem, int nbPass) {
    if (nbPass == 0) {
        return;/*from www  . ja  v a 2  s.  co m*/
    }

    boolean lazyChilds = nbPass > 2;
    DirectoryLazyCheckableTreeItem currentItemValue = currentItem.getValue();
    final ExcludeTreeController excludeControllerInstance = this;

    File currentDirectory = new File(currentItemValue.getAbsolutePath());
    if (!currentDirectory.canRead()) {
        return;
    }

    currentItemValue.setLoaded(lazyChilds);
    currentItem.getChildren().clear();

    for (File subFile : currentDirectory.listFiles(directoryFilter)) {
        DirectoryLazyCheckableTreeItem childrenDirectoryLazyCheckableTreeItem = this.factoryDirectoryCheckableTreeItem
                .createItem(subFile.getAbsolutePath());
        CheckBoxTreeItem<DirectoryLazyCheckableTreeItem> children = new CheckBoxTreeItem<>(
                childrenDirectoryLazyCheckableTreeItem);
        children.setSelected(!this.getModel().isExcludedByUser(subFile.toPath()));
        final ExcludeModel excludeModel = this.getModel();
        final File tmpFile = subFile;
        children.selectedProperty().addListener(new ChangeListener<Boolean>() {
            @Override
            public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue,
                    Boolean newValue) {
                if (newValue) {
                    excludeModel.removeExclusionByUser(tmpFile.toPath());
                } else {
                    excludeModel.addExclusionByUser(tmpFile.toPath());
                }
            }
        });

        this.buildTreeLazily(children, nbPass - 1);
        currentItem.getChildren().add(children);
    }

    if (nbPass == 2) {
        currentItem.expandedProperty().addListener(new ChangeListener<Boolean>() {
            @Override
            public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue,
                    Boolean newValue) {
                excludeControllerInstance.buildTreeLazily(currentItem, 3);
                currentItem.expandedProperty().removeListener(this);
            }
        });
    }

}