Search in sources :

Example 1 with Callback

use of javafx.util.Callback in project JFoenix by jfoenixadmin.

the class JFXNodesList method addAnimatedNode.

/**
	 * add node to list with a specified callback that is triggered after the node animation is finished. 
	 * Note: this method must be called instead of getChildren().add().
	 * 
	 * @param node
	 */
public void addAnimatedNode(Region node, Callback<Boolean, ArrayList<KeyValue>> animationCallBack) {
    // create container for the node if it's a sub nodes list
    if (node instanceof JFXNodesList) {
        StackPane container = new StackPane(node);
        container.setPickOnBounds(false);
        addAnimatedNode(container, animationCallBack);
        return;
    }
    // init node property
    node.setVisible(false);
    node.minWidthProperty().bind(node.prefWidthProperty());
    node.minHeightProperty().bind(node.prefHeightProperty());
    if (this.getChildren().size() > 0)
        initNode(node);
    else {
        if (node instanceof Button)
            ((Button) node).setOnAction((action) -> this.animateList());
        else
            node.setOnMouseClicked((click) -> this.animateList());
        node.getStyleClass().add("trigger-node");
    }
    // init the list height and width
    if (this.getChildren().size() == 0) {
        node.setVisible(true);
        this.minHeightProperty().bind(node.prefHeightProperty());
        this.maxHeightProperty().bind(node.prefHeightProperty());
        this.minWidthProperty().bind(node.prefWidthProperty());
        this.maxWidthProperty().bind(node.prefWidthProperty());
    }
    // add the node and its listeners
    this.getChildren().add(node);
    this.rotateProperty().addListener((o, oldVal, newVal) -> node.setRotate(newVal.doubleValue() % 180 == 0 ? newVal.doubleValue() : -newVal.doubleValue()));
    if (animationCallBack == null && this.getChildren().size() != 1)
        animationCallBack = (expanded) -> {
            return initDefaultAnimation(node, expanded);
        };
    else if (animationCallBack == null && this.getChildren().size() == 1)
        animationCallBack = (expanded) -> {
            return new ArrayList<KeyValue>();
        };
    animationsMap.put(node, animationCallBack);
}
Also used : Button(javafx.scene.control.Button) KeyFrame(javafx.animation.KeyFrame) Status(javafx.animation.Animation.Status) Node(javafx.scene.Node) Timeline(javafx.animation.Timeline) StackPane(javafx.scene.layout.StackPane) HashMap(java.util.HashMap) VBox(javafx.scene.layout.VBox) ArrayList(java.util.ArrayList) Duration(javafx.util.Duration) Region(javafx.scene.layout.Region) Interpolator(javafx.animation.Interpolator) KeyValue(javafx.animation.KeyValue) Callback(javafx.util.Callback) Button(javafx.scene.control.Button) ArrayList(java.util.ArrayList) StackPane(javafx.scene.layout.StackPane)

Example 2 with Callback

use of javafx.util.Callback in project DistributedFractalNetwork by Budder21.

the class FractalEditor method initialize.

/**
	 * Initializes the menus and fractal
	 *
	 * @author David
	 *
	 * @throws FileNotFoundException
	 * @throws AWTException
	 */
@SuppressWarnings({ "rawtypes", "unchecked", "static-access" })
public void initialize() throws FileNotFoundException, AWTException {
    // initializing stuff
    Layer.initializeFractalRegistry();
    File fractalDirectory = new File(Constants.FRACTAL_FILEPATH);
    if (!fractalDirectory.exists()) {
        fractalDirectory.mkdirs();
        try {
            fractalDirectory.createNewFile();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
    fractal = new RenderManager();
    MenuBar menu = new MenuBar();
    SwingNode fractalEditor = new SwingNode();
    TreeView parameters = new TreeView();
    layers = new TreeView();
    VBox trees = new VBox();
    trees.minHeightProperty().bind(bp.minHeightProperty().subtract(menu.minHeightProperty()));
    trees.minWidthProperty().bind(bp.minWidthProperty().divide(6));
    Button render = new Button("Update");
    render.minWidthProperty().bind(trees.minWidthProperty());
    render.minHeightProperty().bind(trees.minHeightProperty().divide(6));
    fractalView = new ImageView();
    fractalView.setOnMouseClicked(e -> {
        Point p = new Point(e.getScreenX(), e.getScreenY() - 52);
        double screenDistX = fractalView.getFitWidth() / 2 - p.x;
        double screenDistY = fractalView.getFitHeight() / 2 - p.y;
        double realDistX = -screenDistX * fractal.getRealResolution().x / fractal.getScreenResolution().width;
        double realDistY = screenDistY * fractal.getRealResolution().y / fractal.getScreenResolution().height;
        fractal.setLocation(new Point(fractal.getLocation().x + realDistX * 2, fractal.getLocation().y + realDistY * 2));
        this.updateFractalImage();
    });
    fractalView.setOnMouseEntered(e -> {
        zoom = true;
    });
    fractalView.setOnMouseExited(e -> {
        zoom = false;
    });
    this.setOnKeyPressed(e -> {
        if (zoom)
            if (e.getCode() == KeyCode.COMMA) {
                this.fractal.setZoom(this.fractal.getZoom() * 1.5);
                updateFractalImage();
            } else if (e.getCode() == KeyCode.PERIOD) {
                this.fractal.setZoom(this.fractal.getZoom() / 1.5);
                updateFractalImage();
            }
    });
    fractalView.setOnScroll(e -> {
        double zoom = e.getDeltaY() > 0 ? 1 / .9 : .9;
        this.fractal.setZoom(this.fractal.getZoom() * zoom);
        this.updateFractalImage();
    });
    this.fractal = new RenderManager();
    render.setOnAction(e -> {
        updateFractalImage();
    });
    // Fitting the image to the screen
    fractalView.fitWidthProperty().bind(bp.minWidthProperty().subtract(trees.minWidthProperty()));
    fractalView.fitHeightProperty().bind(bp.heightProperty().subtract(menu.minHeightProperty()).subtract(220));
    {
        // Fitting gradientEditor to full screen
        Dimension p = new Dimension((int) (Toolkit.getDefaultToolkit().getScreenSize().width * 0.75), 200);
        System.out.println("Gradient Dimensions: " + p);
        gradient = new Window(p, 50, this.fractal.getLayers().get(0));
    }
    {
        // Tree Stuff
        parameters.setRoot(new TreeItem("params"));
        parameters.getRoot().setExpanded(true);
        TreeItem xPos = new TreeItem();
        parameters.getRoot().getChildren().addAll(xPos);
        layers.setRoot(new TreeItem());
        layers.getRoot().setExpanded(true);
        layers.setShowRoot(false);
        layers.setEditable(true);
        /**
			 * layers.setCellFactory(new Callback<TreeView,CheckBoxTreeCell>(){
			 *
			 * @Override public CheckBoxTreeCell call(TreeView p) { return new
			 *           CheckBoxTreeCell(); } });
			 */
        // Use a custom callback to determine the style of the tree item
        layers.setCellFactory(new Callback<TreeView, TreeCell>() {

            @Override
            public TreeCell call(TreeView param) {
                return new CheckBoxTreeCell() {

                    @Override
                    public void updateItem(Object item, boolean empty) {
                        super.updateItem(item, empty);
                        // empty
                        if (empty) {
                            setGraphic(null);
                            setText(null);
                        // Otherwise if it's not representation as an
                        // item of the tree
                        // is not a CheckBoxTreeItem, remove the
                        // checkbox item
                        } else if (!(getTreeItem() instanceof CheckBoxTreeItem)) {
                            BufferedImage image;
                            try {
                                image = ImageIO.read(new File("textures\\plusButton.png"));
                                Image plusImage = SwingFXUtils.toFXImage(image, null);
                                ImageView plusView = new ImageView(plusImage);
                                plusView.setFitHeight(16);
                                plusView.setFitWidth(16);
                                setGraphic(plusView);
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                };
            }
        });
        TreeItem add = new TreeItem();
        /**
			 * try{ BufferedImage image = ImageIO.read(new
			 * File("textures\\plusButton.jpg")); Image plusImage =
			 * SwingFXUtils.toFXImage(image, null); ImageView plusView = new
			 * ImageView(plusImage); plusView.setFitWidth(16);
			 * plusView.setFitHeight(16); add.setGraphic(plusView);
			 * }catch(Exception e){ e.printStackTrace(); }
			 */
        layerIndex = 1;
        CheckBoxTreeItem item = getNewTreeItem();
        /**
			 * add.addEventHandler(CheckBoxTreeItem.checkBoxSelectionChangedEvent(),
			 * e -> { if(((CheckBoxTreeItem)(e.getSource())).isSelected()){
			 * ((CheckBoxTreeItem)(e.getSource())).getParent().getChildren().add(0,
			 * new CheckBoxTreeItem(new
			 * MetaLayer("Layer"+incrementLayers(),null)));
			 * ((CheckBoxTreeItem)(e.getSource())).setSelected(false); }});
			 */
        layers.setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent mouseEvent) {
                if (mouseEvent.getClickCount() == 2) {
                    if (layers.getSelectionModel().getSelectedItem() == add) {
                        CheckBoxTreeItem i = getNewTreeItem();
                        layers.getRoot().getChildren().add(0, i);
                        fractal.addLayer("HistogramLayer");
                    } else {
                        ((TreeItem) layers.getSelectionModel().getSelectedItem()).setValue(LayerBox.display((TreeItem<MetaLayer>) layers.getSelectionModel().getSelectedItem()));
                        MetaLayer meta = ((MetaLayer) ((TreeItem) layers.getSelectionModel().getSelectedItem()).getValue());
                        int index = layers.getRoot().getChildren().size() - 2 - layers.getRoot().getChildren().indexOf(layers.getSelectionModel().getSelectedItem());
                        Layer l = fractal.getLayers().get(index);
                        if (meta.getType() != l.getClass().getSimpleName()) {
                            Layer newLayer = Layer.getLayerByType(meta.getType());
                            newLayer.init(new Palette(), index + 1);
                            fractal.getLayers().set(index, newLayer);
                            fractal.update();
                        }
                        fractal.getLayers().get(index).setName(meta.getName());
                        updateFractalImage();
                    }
                } else if (mouseEvent.getClickCount() == 1 && layers.getSelectionModel().getSelectedItem() != add) {
                    int index = layers.getRoot().getChildren().size() - 2 - layers.getRoot().getChildren().indexOf(layers.getSelectionModel().getSelectedItem());
                    Layer l = fractal.getLayers().get(index);
                    gradient.updateLayer(l);
                }
            }
        });
        layers.getRoot().getChildren().addAll(item, add);
        {
        // TODO I DONT KNOW WHY THIS ISNT WORKING IUEAWBIUBFAI
        /**
				 * layers.getRoot().addEventHandler(layers.getRoot().childrenModificationEvent(),e
				 * -> { for(Object i :((TreeItem)e.getSource()).getChildren()){
				 * if(i!=add)
				 * if(((MetaLayer)((TreeItem)(i)).getValue()).isDelete()){
				 * layers.getSelectionModel().select(i);
				 * layers.getSelectionModel().clearSelection(); } } });
				 */
        }
    }
    // Trying to get this to work
    fractalEditor.setOnMouseEntered(e -> gradient.repaint());
    {
        // This is the menu stuff
        Menu network = new Menu("Network");
        Menu fractal = new Menu("Fractal");
        Menu system = new Menu("System");
        MenuItem newNet = new MenuItem("Create New Network");
        MenuItem viewNetLog = new MenuItem("View Network Log");
        MenuItem viewNet = new MenuItem("View Network");
        MenuItem endNet = new MenuItem("Close Network");
        newNet.setOnAction(e -> {
            NetworkCreationTool createNet = new NetworkCreationTool();
            if (createNet.createNetwork()) {
                this.network = createNet.getServer();
                this.network.init(log);
                Alert alert = new Alert(AlertType.INFORMATION);
                alert.setTitle("Network Message");
                alert.setHeaderText(null);
                alert.setContentText("Network succesfully created.");
                viewNet.setDisable(false);
                endNet.setDisable(false);
                newNet.setDisable(true);
                viewNetLog.setDisable(false);
                alert.showAndWait();
            }
        });
        viewNet.setDisable(true);
        endNet.setDisable(true);
        viewNetLog.setDisable(true);
        viewNet.setOnAction(e -> {
            Display display = new Display(this.network);
            this.network.setDisplay(display);
            display.updateNetworkView(this.network.getChildren(), this.network.getUncompletedJobs());
        });
        endNet.setOnAction(e -> {
            this.network.kill();
            viewNet.setDisable(true);
            endNet.setDisable(true);
            viewNetLog.setDisable(true);
            newNet.setDisable(false);
        });
        viewNetLog.setOnAction(e -> {
            Alert alert = new Alert(AlertType.INFORMATION);
            alert.setTitle("Network Log");
            alert.setHeaderText(null);
            alert.setContentText(this.network.getLog().getLog());
            alert.showAndWait();
        });
        network.getItems().addAll(newNet, viewNet, viewNetLog, endNet);
        MenuItem newFract = new MenuItem("New Fractal");
        newFract.setOnAction(e -> {
            this.fractal = new RenderManager();
            gradient.updateLayer(this.fractal.getLayers().get(0));
            this.updateFractalImage();
        });
        MenuItem openFract = new MenuItem("Open Fractal");
        openFract.setOnAction(e -> {
            FileChooser chooser = new FileChooser();
            chooser.setTitle("Open Fractal");
            chooser.setInitialDirectory(new File("fractals"));
            FileChooser.ExtensionFilter filter = new FileChooser.ExtensionFilter("Fractals (*.fractal)", "*.fractal");
            chooser.getExtensionFilters().add(filter);
            File f = chooser.showOpenDialog(null);
            this.fractal = new RenderManager(f);
            gradient.updateLayer(this.fractal.getLayers().get(0));
            this.updateFractalImage();
        });
        MenuItem saveFract = new MenuItem("Save Fractal");
        saveFract.setOnAction(e -> {
            this.fractal.saveFractal();
        });
        MenuItem saveFractAs = new MenuItem("Save Fractal As");
        saveFractAs.setOnAction(e -> {
            this.fractal.saveFractalAs();
        });
        MenuItem exportFract = new MenuItem("Export Fractal");
        exportFract.setOnAction(e -> {
            ExportImageTool export = new ExportImageTool();
            export.exportImage(this.fractal);
        });
        fractal.getItems().addAll(newFract, openFract, saveFract, saveFractAs, exportFract);
        MenuItem newLayer = new MenuItem("New Layer Type");
        newLayer.setOnAction(e -> {
            RegisterLayerTool register = new RegisterLayerTool();
            register.registerLayer();
            Layer.registerLayer(register.getFile());
        });
        MenuItem changeLog = new MenuItem("Edit Log Options");
        changeLog.setOnAction(e -> {
        });
        system.getItems().addAll(newLayer, changeLog);
        menu.getMenus().addAll(fractal);
        menu.getMenus().addAll(network);
        menu.getMenus().addAll(system);
    }
    VBox center = new VBox();
    center.getChildren().addAll(fractalView, fractalEditor);
    trees.getChildren().addAll(parameters, layers, render);
    bp.setCenter(center);
    bp.setRight(trees);
    // This is where the menu is located on the border pane
    bp.setTop(menu);
    bp.minWidthProperty().bind(this.widthProperty());
    bp.minHeightProperty().bind(this.heightProperty());
    fractalEditor.setContent(gradient);
    fractalEditor.minHeight(200);
}
Also used : EventHandler(javafx.event.EventHandler) Button(javafx.scene.control.Button) Scene(javafx.scene.Scene) RegisterLayerTool(menus.RegisterLayerTool) Server(server.Server) TreeItem(javafx.scene.control.TreeItem) MouseEvent(javafx.scene.input.MouseEvent) Log(util.Log) ChoiceDialog(javafx.scene.control.ChoiceDialog) VBox(javafx.scene.layout.VBox) TreeModificationEvent(javafx.scene.control.CheckBoxTreeItem.TreeModificationEvent) Constants(util.Constants) ArrayList(java.util.ArrayList) AlertType(javafx.scene.control.Alert.AlertType) ImageIO(javax.imageio.ImageIO) Layer(fractal.Layer) Callback(javafx.util.Callback) Alert(javafx.scene.control.Alert) KeyCode(javafx.scene.input.KeyCode) MenuBar(javafx.scene.control.MenuBar) MenuItem(javafx.scene.control.MenuItem) BufferedImage(java.awt.image.BufferedImage) IOException(java.io.IOException) RenderManager(fractal.RenderManager) ExportImageTool(menus.ExportImageTool) CheckBoxTreeCell(javafx.scene.control.cell.CheckBoxTreeCell) Point(util.Point) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) TreeView(javafx.scene.control.TreeView) Menu(javafx.scene.control.Menu) Display(menus.Display) NetworkCreationTool(menus.NetworkCreationTool) CheckBoxTreeItem(javafx.scene.control.CheckBoxTreeItem) FileChooser(javafx.stage.FileChooser) Dimension(java.awt.Dimension) List(java.util.List) Palette(fractal.Palette) ImageView(javafx.scene.image.ImageView) AWTException(java.awt.AWTException) SwingFXUtils(javafx.embed.swing.SwingFXUtils) TreeCell(javafx.scene.control.TreeCell) BorderPane(javafx.scene.layout.BorderPane) Image(javafx.scene.image.Image) SwingNode(javafx.embed.swing.SwingNode) Toolkit(java.awt.Toolkit) Palette(fractal.Palette) TreeItem(javafx.scene.control.TreeItem) CheckBoxTreeItem(javafx.scene.control.CheckBoxTreeItem) MenuBar(javafx.scene.control.MenuBar) EventHandler(javafx.event.EventHandler) BufferedImage(java.awt.image.BufferedImage) Image(javafx.scene.image.Image) BufferedImage(java.awt.image.BufferedImage) SwingNode(javafx.embed.swing.SwingNode) CheckBoxTreeCell(javafx.scene.control.cell.CheckBoxTreeCell) Button(javafx.scene.control.Button) FileChooser(javafx.stage.FileChooser) ImageView(javafx.scene.image.ImageView) Menu(javafx.scene.control.Menu) RenderManager(fractal.RenderManager) MouseEvent(javafx.scene.input.MouseEvent) CheckBoxTreeItem(javafx.scene.control.CheckBoxTreeItem) MenuItem(javafx.scene.control.MenuItem) IOException(java.io.IOException) Point(util.Point) Dimension(java.awt.Dimension) Layer(fractal.Layer) Point(util.Point) ExportImageTool(menus.ExportImageTool) Callback(javafx.util.Callback) NetworkCreationTool(menus.NetworkCreationTool) TreeView(javafx.scene.control.TreeView) Alert(javafx.scene.control.Alert) File(java.io.File) VBox(javafx.scene.layout.VBox) RegisterLayerTool(menus.RegisterLayerTool) Display(menus.Display)

Example 3 with Callback

use of javafx.util.Callback in project Retrospector by NonlinearFruit.

the class SearchTabController method initSearchTab.

private void initSearchTab() {
    searchEditMedia.setDisable(true);
    searchDeleteMedia.setDisable(true);
    // Table Double Click
    searchTable.setRowFactory(tv -> {
        TableRow<Media> row = new TableRow<>();
        row.setOnMouseClicked(event -> {
            if (event.getClickCount() == 2 && (!row.isEmpty())) {
                setMedia(row.getItem());
                setTab(TAB.MEDIA);
            }
        });
        return row;
    });
    // Table data setup
    searchTableData = DataManager.getMedia();
    FilteredList<Media> mediaFiltered = new FilteredList(searchTableData, x -> true);
    SortedList<Media> mediaSortable = new SortedList<>(mediaFiltered);
    searchTable.setItems(mediaSortable);
    mediaSortable.comparatorProperty().bind(searchTable.comparatorProperty());
    // Link to data properties
    searchTitleColumn.setCellValueFactory(new PropertyValueFactory<>("Title"));
    searchCreatorColumn.setCellValueFactory(new PropertyValueFactory<>("Creator"));
    searchSeasonColumn.setCellValueFactory(new PropertyValueFactory<>("SeasonId"));
    searchEpisodeColumn.setCellValueFactory(new PropertyValueFactory<>("EpisodeId"));
    searchCategoryColumn.setCellValueFactory(new PropertyValueFactory<>("Category"));
    // Values for special columns
    searchNumberColumn.setSortable(false);
    searchNumberColumn.setCellValueFactory(p -> new ReadOnlyObjectWrapper(1 + searchTable.getItems().indexOf(p.getValue())));
    searchReviewsColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Media, Integer>, ObservableValue<Integer>>() {

        @Override
        public ObservableValue<Integer> call(TableColumn.CellDataFeatures<Media, Integer> p) {
            return new ReadOnlyObjectWrapper(p.getValue().getReviews().size());
        }
    });
    searchMeanRColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Media, BigDecimal>, ObservableValue<BigDecimal>>() {

        @Override
        public ObservableValue<BigDecimal> call(TableColumn.CellDataFeatures<Media, BigDecimal> p) {
            return new ReadOnlyObjectWrapper(p.getValue().getAverageRating());
        }
    });
    searchCurrentRColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Media, BigDecimal>, ObservableValue<BigDecimal>>() {

        @Override
        public ObservableValue<BigDecimal> call(TableColumn.CellDataFeatures<Media, BigDecimal> p) {
            return new ReadOnlyObjectWrapper(p.getValue().getCurrentRating());
        }
    });
    // Comparators for string columns
    searchTitleColumn.setComparator(new NaturalOrderComparator());
    searchCreatorColumn.setComparator(new NaturalOrderComparator());
    searchSeasonColumn.setComparator(new NaturalOrderComparator());
    searchEpisodeColumn.setComparator(new NaturalOrderComparator());
    searchCategoryColumn.setComparator(new NaturalOrderComparator());
    searchTable.getSelectionModel().selectedItemProperty().addListener((observe, old, neo) -> {
        setMedia(neo);
    });
    searchBox.textProperty().addListener((observa, old, neo) -> {
        String query = neo;
        if (query == null || query.equals(""))
            mediaFiltered.setPredicate(x -> true);
        else {
            String[] queries = query.split(":");
            mediaFiltered.setPredicate(x -> QueryProcessor.isMatchForMedia(query, x));
        }
        updateStats();
    });
    // Buttons
    searchNewMedia.setOnAction(e -> {
        Media neo = new Media();
        neo.setId(DataManager.createDB(neo));
        setMedia(neo);
        setTab(TAB.MEDIA);
    });
    searchQuickEntry.setOnAction(e -> {
        try {
            FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("QuickEntry.fxml"));
            Parent root1 = (Parent) fxmlLoader.load();
            QuickEntryController qec = fxmlLoader.getController();
            qec.setup(currentTab);
            Stage stage = new Stage();
            stage.setTitle("Quick Entry");
            stage.setScene(new Scene(root1));
            stage.show();
        } catch (Exception ex) {
        }
    });
    searchStandardEntry.setOnAction(e -> {
        Media neo = new Media();
        neo.setId(DataManager.createDB(neo));
        setMedia(neo);
        setTab(TAB.MEDIA);
    });
    searchBackup.setOnAction(e -> DataManager.makeBackup());
    searchCheatsheet.setOnAction(e -> {
        new Cheatsheet().start(new Stage());
    });
    searchEditMedia.setOnAction(e -> {
        setTab(TAB.MEDIA);
    });
    searchDeleteMedia.setOnAction(e -> {
        if (new Alert(Alert.AlertType.WARNING, "Are you sure you want to delete this?", ButtonType.NO, ButtonType.YES).showAndWait().get().equals(ButtonType.YES)) {
            DataManager.deleteDB(getMedia());
            updateSearchTab();
        }
    });
    // Init stuff
    updateStats();
}
Also used : Button(javafx.scene.control.Button) Scene(javafx.scene.Scene) Arrays(java.util.Arrays) Initializable(javafx.fxml.Initializable) URL(java.net.URL) ButtonType(javafx.scene.control.ButtonType) Factoid(retrospector.model.Factoid) ArrayList(java.util.ArrayList) TableColumn(javafx.scene.control.TableColumn) Media(retrospector.model.Media) Application(javafx.application.Application) BigDecimal(java.math.BigDecimal) Parent(javafx.scene.Parent) ResourceBundle(java.util.ResourceBundle) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) FXMLLoader(javafx.fxml.FXMLLoader) QuickEntryController(retrospector.fxml.QuickEntryController) NaturalOrderComparator(retrospector.util.NaturalOrderComparator) TableView(javafx.scene.control.TableView) Callback(javafx.util.Callback) SortedList(javafx.collections.transformation.SortedList) Alert(javafx.scene.control.Alert) ObjectProperty(javafx.beans.property.ObjectProperty) TextField(javafx.scene.control.TextField) MenuItem(javafx.scene.control.MenuItem) Review(retrospector.model.Review) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) TableRow(javafx.scene.control.TableRow) FilteredList(javafx.collections.transformation.FilteredList) TAB(retrospector.fxml.CoreController.TAB) FXML(javafx.fxml.FXML) Text(javafx.scene.text.Text) List(java.util.List) Stage(javafx.stage.Stage) MenuButton(javafx.scene.control.MenuButton) ObservableValue(javafx.beans.value.ObservableValue) ObservableList(javafx.collections.ObservableList) DataManager(retrospector.model.DataManager) QuickEntryController(retrospector.fxml.QuickEntryController) Parent(javafx.scene.Parent) SortedList(javafx.collections.transformation.SortedList) ObservableValue(javafx.beans.value.ObservableValue) FXMLLoader(javafx.fxml.FXMLLoader) FilteredList(javafx.collections.transformation.FilteredList) Stage(javafx.stage.Stage) Media(retrospector.model.Media) Scene(javafx.scene.Scene) TableColumn(javafx.scene.control.TableColumn) BigDecimal(java.math.BigDecimal) NaturalOrderComparator(retrospector.util.NaturalOrderComparator) TableRow(javafx.scene.control.TableRow) Alert(javafx.scene.control.Alert) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper)

Example 4 with Callback

use of javafx.util.Callback 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 5 with Callback

use of javafx.util.Callback in project SmartCity-Market by TechnionYP5777.

the class ManageEmployeesTab method initialize.

@Override
public void initialize(URL location, ResourceBundle __) {
    userTxt.textProperty().addListener((observable, oldValue, newValue) -> enableFinishBtn());
    passTxt.textProperty().addListener((observable, oldValue, newValue) -> enableFinishBtn());
    securityAnswerTxt.textProperty().addListener((observable, oldValue, newValue) -> enableFinishBtn());
    radioBtnCont.addRadioButtons(Arrays.asList(new RadioButton[] { workerRadioBtn, managerRadioBtn }));
    securityCombo.getItems().addAll(SecurityQuestions.getQuestions());
    RequiredFieldValidator validator2 = new RequiredFieldValidator();
    validator2.setMessage("Input Required");
    validator2.setIcon(GlyphsBuilder.create(FontAwesomeIconView.class).glyph(FontAwesomeIcon.WARNING).size("1em").styleClass("error").build());
    userTxt.getValidators().add(validator2);
    userTxt.focusedProperty().addListener((o, oldVal, newVal) -> {
        if (!newVal)
            userTxt.validate();
    });
    RequiredFieldValidator validator3 = new RequiredFieldValidator();
    validator3.setMessage("Input Required");
    validator3.setIcon(GlyphsBuilder.create(FontAwesomeIconView.class).glyph(FontAwesomeIcon.WARNING).size("1em").styleClass("error").build());
    passTxt.getValidators().add(validator3);
    passTxt.focusedProperty().addListener((o, oldVal, newVal) -> {
        if (!newVal)
            passTxt.validate();
    });
    RequiredFieldValidator validator4 = new RequiredFieldValidator();
    validator4.setMessage("Input Required");
    validator4.setIcon(GlyphsBuilder.create(FontAwesomeIconView.class).glyph(FontAwesomeIcon.WARNING).size("1em").styleClass("error").build());
    securityAnswerTxt.getValidators().add(validator4);
    securityAnswerTxt.focusedProperty().addListener((o, oldVal, newVal) -> {
        if (!newVal)
            securityAnswerTxt.validate();
    });
    createEmployeesList();
    searchEmployee.textProperty().addListener(obs -> {
        String filter = searchEmployee.getText();
        filteredDataEmployees.setPredicate(filter == null || filter.length() == 0 ? s -> true : s -> s.contains(filter));
    });
    employeesList.setCellFactory(CheckBoxListCell.forListView(new Callback<String, ObservableValue<Boolean>>() {

        @Override
        public ObservableValue<Boolean> call(String item) {
            BooleanProperty observable = new SimpleBooleanProperty();
            observable.set(selectedEmployees.contains(item));
            observable.addListener((obs, wasSelected, isNowSelected) -> {
                if (isNowSelected)
                    selectedEmployees.add(item);
                else
                    selectedEmployees.remove(item);
                enableRemoveButton();
            });
            return observable;
        }
    }));
    securityCombo.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>() {

        @Override
        public void changed(ObservableValue<? extends String> __, String oldValue, String newValue) {
            enableFinishBtn();
        }
    });
    enableFinishBtn();
    enableRemoveButton();
}
Also used : JFXButton(com.jfoenix.controls.JFXButton) Arrays(java.util.Arrays) Initializable(javafx.fxml.Initializable) GlyphsBuilder(de.jensd.fx.glyphs.GlyphsBuilder) JFXPasswordField(com.jfoenix.controls.JFXPasswordField) URL(java.net.URL) CheckBoxListCell(javafx.scene.control.cell.CheckBoxListCell) FXCollections(javafx.collections.FXCollections) EmployeeNotConnected(EmployeeDefs.AEmployeeException.EmployeeNotConnected) HashSet(java.util.HashSet) Logger(org.apache.log4j.Logger) RequiredFieldValidator(com.jfoenix.validation.RequiredFieldValidator) ForgotPasswordData(BasicCommonClasses.ForgotPasswordData) ResourceBundle(java.util.ResourceBundle) Map(java.util.Map) SecurityQuestions(GuiUtils.SecurityQuestions) FontAwesomeIconView(de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView) ConnectionFailure(EmployeeDefs.AEmployeeException.ConnectionFailure) JFXComboBox(com.jfoenix.controls.JFXComboBox) Callback(javafx.util.Callback) CriticalError(SMExceptions.CommonExceptions.CriticalError) RadioButtonEnabler(GuiUtils.RadioButtonEnabler) StackTraceUtil(UtilsImplementations.StackTraceUtil) JFXListView(com.jfoenix.controls.JFXListView) FilteredList(javafx.collections.transformation.FilteredList) Manager(EmployeeImplementations.Manager) WorkerAlreadyExists(EmployeeDefs.AEmployeeException.WorkerAlreadyExists) FXML(javafx.fxml.FXML) InjectionFactory(UtilsImplementations.InjectionFactory) BooleanProperty(javafx.beans.property.BooleanProperty) ActionEvent(javafx.event.ActionEvent) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) JFXRadioButton(com.jfoenix.controls.JFXRadioButton) WorkerDoesNotExist(EmployeeDefs.AEmployeeException.WorkerDoesNotExist) RadioButton(javafx.scene.control.RadioButton) FontAwesomeIcon(de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon) IManager(EmployeeContracts.IManager) ObservableValue(javafx.beans.value.ObservableValue) Login(BasicCommonClasses.Login) ObservableList(javafx.collections.ObservableList) ChangeListener(javafx.beans.value.ChangeListener) JFXTextField(com.jfoenix.controls.JFXTextField) InvalidParameter(EmployeeDefs.AEmployeeException.InvalidParameter) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) Callback(javafx.util.Callback) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) JFXRadioButton(com.jfoenix.controls.JFXRadioButton) RadioButton(javafx.scene.control.RadioButton) FontAwesomeIconView(de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView) RequiredFieldValidator(com.jfoenix.validation.RequiredFieldValidator)

Aggregations

Callback (javafx.util.Callback)43 Inject (javax.inject.Inject)27 FxmlView (io.bitsquare.gui.common.view.FxmlView)26 javafx.scene.control (javafx.scene.control)25 Popup (io.bitsquare.gui.main.overlays.popups.Popup)24 ReadOnlyObjectWrapper (javafx.beans.property.ReadOnlyObjectWrapper)23 ObservableList (javafx.collections.ObservableList)22 FXML (javafx.fxml.FXML)22 VBox (javafx.scene.layout.VBox)21 HyperlinkWithIcon (io.bitsquare.gui.components.HyperlinkWithIcon)20 BSFormatter (io.bitsquare.gui.util.BSFormatter)20 SortedList (javafx.collections.transformation.SortedList)19 ImageView (javafx.scene.image.ImageView)18 ChangeListener (javafx.beans.value.ChangeListener)17 GUIUtil (io.bitsquare.gui.util.GUIUtil)16 FXCollections (javafx.collections.FXCollections)16 Insets (javafx.geometry.Insets)15 AwesomeIcon (de.jensd.fx.fontawesome.AwesomeIcon)13 UserThread (io.bitsquare.common.UserThread)13 ActivatableView (io.bitsquare.gui.common.view.ActivatableView)13