Example usage for javafx.scene.control ScrollPane getContent

List of usage examples for javafx.scene.control ScrollPane getContent

Introduction

In this page you can find the example usage for javafx.scene.control ScrollPane getContent.

Prototype

public final Node getContent() 

Source Link

Usage

From source file:ipat_fx.FXMLDocumentController.java

@FXML
public void resetScores() {

    HashMap<String, Hint> hintMap = controller.hints;
    TabPane tabpane = (TabPane) byProfilePane.getChildren().get(0);
    Tab tab = null;//from   www. ja v a  2  s. co m
    if (tabFlag.equalsIgnoreCase("byProfile")) {
        tab = tabpane.getTabs().get(0);
    } else if (tabFlag.equalsIgnoreCase("byImage")) {
        tab = tabpane.getTabs().get(0);
    } else {
        Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null,
                "Something wrong with tabFlag");
    }
    ScrollPane scrollPane = (ScrollPane) tab.getContent();
    FlowPane flowPane = (FlowPane) scrollPane.getContent();
    Iterator<Node> cellsIterator = flowPane.getChildren().iterator();
    while (cellsIterator.hasNext()) {
        GridPane cell = (GridPane) cellsIterator.next();
        Iterator<Node> cellIterator = cell.getChildren().iterator();
        while (cellIterator.hasNext()) {
            Node cellElement = cellIterator.next();
            if (cellElement instanceof Slider) {
                Set<String> keySet = hintMap.keySet();// get the hints one by one and apply to cell
                int keyCount = 0;
                for (String key : keySet) {
                    Hint h = hintMap.get(key);
                    Slider slider = ((Slider) cellElement);
                    String[] split = slider.getId().split("_");
                    if (split[0].equalsIgnoreCase(h.getHintName())) {
                        slider.setValue(Double.valueOf(h.getDefaultValue()));
                    }
                }
            }
            if (cellElement instanceof CheckBox) {
                ((CheckBox) cellElement).setSelected(false);
            }
        }
    }
}

From source file:ipat_fx.FXMLDocumentController.java

@FXML
public void nextGeneration() {

    //check if num of profiles is a valid input 
    int numOfProfiles = Integer.parseInt(noOfProfiles.getText());
    if (numOfProfiles > 8) {
        JOptionPane.showMessageDialog(null, "Please make the number of profiles smaller than 8.");
    } else {//from  w  w w .  j a  v  a 2  s  .  c  om
        HashMap<String, Object> scores = new HashMap<>();
        // TODO get the scores from the user input to then get the next gen

        ObservableList<Tab> tabs = null;

        if (tabFlag.equalsIgnoreCase("byImage")) {
            tabs = byImageTab.getTabs();
        } else if (tabFlag.equalsIgnoreCase("byProfile")) {
            tabs = byProfileTab.getTabs();
        } else {
            System.out.println("Something is wrong with tabFlag in FXML DOC CONT");
        }

        Iterator<Tab> profileTabIterator = tabs.iterator();
        while (profileTabIterator.hasNext()) {
            Tab profileTab = profileTabIterator.next();
            ScrollPane scrollPane = (ScrollPane) profileTab.getContent();
            FlowPane cells = (FlowPane) scrollPane.getContent();
            Iterator<Node> cellIterator = cells.getChildren().iterator();
            while (cellIterator.hasNext()) {
                GridPane cell = (GridPane) cellIterator.next();
                Iterator<Node> nodeIterator = cell.getChildren().iterator();
                while (nodeIterator.hasNext()) {
                    Node cellElement = nodeIterator.next();
                    if (cellElement instanceof Slider) {
                        scores.put(cellElement.getId(), String.valueOf(((Slider) cellElement).getValue()));
                    }
                    if (cellElement instanceof CheckBox) {
                        scores.put(cellElement.getId(), ((CheckBox) cellElement).isSelected());
                    }
                }
            }
        }

        HashMap<String, Object> display = controller.mainloop(scores, numOfProfiles);
        WebView previewView = (WebView) display.get("previewView");
        previewPane.getChildren().add(previewView);
        @SuppressWarnings("unchecked")
        HashMap<String, ArrayList<GridPane>> map = (HashMap<String, ArrayList<GridPane>>) display
                .get("results");

        if (tabFlag.equalsIgnoreCase("byImage")) {
            byImageTab = getByImage(map);
            byImagePane.setCenter(byImageTab);
        } else if (tabFlag.equalsIgnoreCase("byProfile")) {
            byProfileTab = getByProfile(map, numOfProfiles);
            byProfilePane.setCenter(byProfileTab);
        }

        tabPane.getSelectionModel().selectedIndexProperty()
                .addListener((ObservableValue<? extends Number> ov, Number oldValue, Number newValue) -> {
                    if (newValue == Number.class.cast(1)) {
                        byImageTab = getByImage(map);
                        byImagePane.setCenter(byImageTab);
                    } else if (newValue == Number.class.cast(0)) {
                        byProfileTab = getByProfile(map, numOfProfiles);
                        byProfilePane.setCenter(byProfileTab);
                    } else {
                        System.out.println("Error this tab has not been created.");
                    }
                });
    }
}