Example usage for javafx.scene.layout TilePane setMinWidth

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

Introduction

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

Prototype

public final void setMinWidth(double value) 

Source Link

Usage

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 {// w  w  w . j  a  v a  2s .  c  om
        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);
        }
    }
}