de.invation.code.toval.graphic.dialog.FileNameDialog Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of TOVAL Show documentation
Show all versions of TOVAL Show documentation
TOVAL comprises a set of java classes for common programming issues. It includes utils for arrays, lists, sets and collections for convenient handling and modification, but also support for mathematic definitions concerning logic (clauses + resolution) together with some algorithms for permutations, powersets and resolution. Additionally it contains a number of types for multisets, matrices with object keys and much more.
The newest version!
package de.invation.code.toval.graphic.dialog;
import java.awt.Window;
import de.invation.code.toval.validate.ParameterException;
import de.invation.code.toval.validate.Validate;
public class FileNameDialog extends ConditionalInputDialog {
private static final String errorMessageFormat = "Invalid file name:\n%s";
private static final String spacesError = "File name contains spaces";
protected String errorMessage = "";
private boolean allowSpaces = false;
protected FileNameDialog(Window parent, String message, String title, boolean allowSpaces) {
super(parent, message, title);
this.allowSpaces = allowSpaces;
}
@Override
protected String getErrorMessage() {
return String.format(errorMessageFormat, errorMessage);
}
@Override
protected boolean isValid(String input) {
try {
Validate.fileName(input);
} catch (ParameterException e) {
errorMessage = e.getMessage();
return false;
}
if(!allowSpaces && input.contains(" ")){
errorMessage = spacesError;
return false;
}
return true;
}
public static String showDialog(Window parent, String message, String title, boolean allowSpaces){
FileNameDialog dialog = new FileNameDialog(parent, message, title, allowSpaces);
return dialog.requestInput();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy