Example usage for javafx.scene.control TextField getLength

List of usage examples for javafx.scene.control TextField getLength

Introduction

In this page you can find the example usage for javafx.scene.control TextField getLength.

Prototype

public final int getLength() 

Source Link

Usage

From source file:net.rptools.tokentool.util.FileSaveUtil.java

public File getFileName(boolean asToken, boolean useNumbering, String tempFileName, TextField fileNameSuffix)
        throws IOException {
    final String _extension;

    _extension = AppConstants.DEFAULT_IMAGE_EXTENSION;

    if (useNumbering) {
        int dragCounter;
        try {/* w w  w .j a v  a 2 s  .  co  m*/
            dragCounter = Integer.parseInt(fileNameSuffix.getText());
        } catch (NumberFormatException e) {
            dragCounter = 0;
        }

        String leadingZeroes = "%0" + fileNameSuffix.getLength() + "d";

        fileNameSuffix.setText(String.format(leadingZeroes, dragCounter + 1));

        if (tempFileName.isEmpty())
            tempFileName = AppConstants.DEFAULT_TOKEN_NAME;

        if (lastFile != null) {
            return new File(lastFile.getParent(),
                    String.format("%s_" + leadingZeroes + _extension, tempFileName, dragCounter));
        } else {
            return new File(String.format("%s_" + leadingZeroes + _extension, tempFileName, dragCounter));
        }
    } else {
        if (lastFile != null)
            if (tempFileName.isEmpty())
                tempFileName = AppConstants.DEFAULT_TOKEN_NAME + _extension;

        if (!tempFileName.endsWith(_extension))
            tempFileName += _extension;

        if (lastFile != null)
            lastFile = new File(lastFile.getParent(), tempFileName);
        else
            lastFile = new File(tempFileName);

        return lastFile;
    }
}