Example usage for javafx.scene.layout TilePane TilePane

List of usage examples for javafx.scene.layout TilePane TilePane

Introduction

In this page you can find the example usage for javafx.scene.layout TilePane TilePane.

Prototype

public TilePane() 

Source Link

Document

Creates a horizontal TilePane layout with prefColumn = 5 and hgap/vgap = 0.

Usage

From source file:org.mskcc.shenkers.view.IntervalViewNGTest.java

public void testStackIntervalView() throws InterruptedException {
    System.out.println("testStackIntervalView");
    int[][] d = new int[][] { { 2, 6 }, { 7, 10 }, { 1, 3 }, { 4, 6 }, { 8, 10 }, { 1, 2 }, { 3, 7 }, { 9, 10 },
            { 1, 2 }, { 3, 5 }, { 6, 7 }, { 8, 10 }, { 2, 5 }, { 8, 10 } };
    List<int[]> asList = Arrays.asList(d);
    Collections.sort(asList, new Comparator<int[]>() {

        @Override/*ww  w .  j  av  a2  s.  co m*/
        public int compare(int[] o1, int[] o2) {
            return o1[0] - o2[0];
        }
    });
    List<TreeRangeSet<Integer>> rows = new ArrayList<>();
    rows.add(TreeRangeSet.create());
    for (int[] r : d) {
        Range<Integer> R = Range.closed(r[0], r[1]);
        int i = 0;
        added: {
            while (i < rows.size()) {
                TreeRangeSet<Integer> set = rows.get(i);
                RangeSet<Integer> intersection = set.subRangeSet(Range.closed(r[0] - 1, r[1] + 1));
                if (intersection.isEmpty()) {
                    set.add(R);
                    break added;
                }
                i++;
            }
            //                Stri i = ;
            TreeRangeSet<Integer> row = TreeRangeSet.create();
            row.add(R);
            rows.add(row);
        }
    }
    TilePane p = new TilePane();
    p.setSnapToPixel(false);
    for (int i = 0; i < rows.size(); i++) {
        p.getChildren().add(get(rows.get(i), 0, 11));
        System.out.println(rows.get(i).toString());
        StringBuilder sb = new StringBuilder(11);
        sb.append(StringUtils.repeat(".", 11));
        for (int j = 0; j < 11; j++) {
            if (rows.get(i).contains(j)) {
                sb.setCharAt(j, 'X');
            }
        }
        System.out.println(sb.toString());
    }
    //        p.prefWidth(100);
    //        p.prefHeight(100);
    ScrollPane sp = new ScrollPane(p);
    ScrollBar sb = new ScrollBar();
    sb.maxProperty().bind(sp.vmaxProperty());
    sb.minProperty().bind(sp.vminProperty());
    sb.visibleAmountProperty().bind(sp.heightProperty().divide(p.prefHeightProperty()));
    sb.setOrientation(Orientation.VERTICAL);
    sp.vvalueProperty().bindBidirectional(sb.valueProperty());
    HiddenSidesPane hsp = new HiddenSidesPane();
    hsp.setContent(sp);
    hsp.setRight(sb);
    sp.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
    sp.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
    p.setOrientation(Orientation.VERTICAL);
    p.prefTileHeightProperty().bind(new SimpleDoubleProperty(40));
    //        p.minHeightProperty().bind(new SimpleDoubleProperty(20).multiply(Bindings.size(p.getChildren())));
    p.prefTileWidthProperty().bind(sp.widthProperty());
    p.prefHeightProperty()
            .bind(new SimpleDoubleProperty(50).multiply(Bindings.size(p.getChildren())).subtract(10));
    p.prefWidthProperty().bind(sp.widthProperty());
    sp.setPadding(Insets.EMPTY);
    p.setVgap(10);

    CountDownLatch l = new CountDownLatch(1);
    Platform.runLater(() -> {

        Stage stage = new Stage();
        stage.setOnHidden(e -> {
            l.countDown();
        });
        Scene scene = new Scene(hsp, 300, 300, Color.GRAY);
        stage.setTitle("JavaFX Scene Graph Demo");
        stage.setScene(scene);
        stage.show();

    });
    l.await();
}

From source file:photobooth.views.ExplorerPane.java

private void init(String dir, int offset, int limit, int directoryLevel) {

    this.getChildren().removeAll(this.getChildren());
    this.dir = dir;
    this.offset = offset;
    this.limit = limit;
    this.directoryLevel = directoryLevel;

    try {//from w  w w .j  ava2 s .  co  m
        addXButton();
    } catch (IOException ex) {
        Logger.getLogger(ExplorerPane.class.getName()).log(Level.SEVERE, null, ex);
    }
    if (directoryLevel > 0) {
        try {
            addUpButton();
        } catch (IOException ex) {
            Logger.getLogger(ExplorerPane.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    addLabel();

    TilePane tile = new TilePane();
    tile.setHgap(12);
    tile.setVgap(12);

    File folder = new File(dir);
    File[] listOfDirs = folder.listFiles(new FileFilter() {

        @Override
        public boolean accept(File file) {
            return file.isDirectory();
        }
    });
    File[] allFileAndDiresctoies = new File[0];
    if (listOfDirs != null) {
        Arrays.sort(listOfDirs);

        File[] listOfImages = folder.listFiles(new FileFilter() {

            @Override
            public boolean accept(File file) {
                String ext = FilenameUtils.getExtension(file.getAbsolutePath());
                return ext.equalsIgnoreCase("jpg") || ext.equalsIgnoreCase("png");
            }
        });
        Arrays.sort(listOfImages);
        allFileAndDiresctoies = new File[listOfDirs.length + listOfImages.length];
        System.arraycopy(listOfDirs, 0, allFileAndDiresctoies, 0, listOfDirs.length);
        System.arraycopy(listOfImages, 0, allFileAndDiresctoies, listOfDirs.length, listOfImages.length);

        File[] subArray = new File[limit];
        int countToCopy = limit;
        if (offset + limit > allFileAndDiresctoies.length) {
            countToCopy -= offset + limit - allFileAndDiresctoies.length;
        }
        System.arraycopy(allFileAndDiresctoies, offset, subArray, 0, countToCopy);

        for (final File file : subArray) {
            if (file == null) {
                break;
            }
            if (file.isFile()) {
                tile.getChildren().add(createImageView(file));
            } else {
                Button button = new Button(file.getName());
                button.setMaxSize(100, 100);
                button.setMinSize(100, 100);
                button.setWrapText(true);
                button.getStyleClass().add("folderButton");

                button.setOnAction(new EventHandler<ActionEvent>() {
                    @Override
                    public void handle(ActionEvent event) {

                        Global.getInstance().setSceneRoot(LoadingPane.getInstance());

                        Platform.runLater(() -> {
                            new Thread(new Runnable() {

                                @Override
                                public void run() {
                                    ExplorerPane.getInstance().setDir(file.getAbsolutePath(), 0, limit,
                                            directoryLevel + 1);
                                    Global.getInstance().setSceneRoot(ExplorerPane.getInstance());
                                }
                            }).start();
                        });

                    }
                });
                tile.getChildren().add(button);

            }
        }
    }
    this.getChildren().add(tile);
    tile.setMinWidth(670);
    tile.setMaxWidth(670);
    tile.setLayoutX(65);
    tile.setLayoutY(70);
    tile.setMaxHeight(390);

    if (allFileAndDiresctoies.length > offset + limit) {
        try {
            addNextButton();
        } catch (IOException ex) {
            Logger.getLogger(ExplorerPane.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    if (offset > 0) {
        try {
            addPrevButton();
        } catch (IOException ex) {
            Logger.getLogger(ExplorerPane.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}