use of org.fagu.fmv.utils.io.UnclosedInputStream in project fmv by f-agu.
the class Bootstrap method newProject.
/**
* @param printStream
* @return
*/
private static Project newProject(PrintStream printStream) {
try (Scanner scanner = new Scanner(new UnclosedInputStream(System.in))) {
// name
printStream.print("Name: ");
String name = scanner.nextLine();
// save file
final File defaultSaveFile = new File(name);
printStream.print("SaveFolder: [" + defaultSaveFile.getAbsolutePath() + "] ");
File saveFile = null;
String ssavefile = scanner.nextLine();
if (StringUtils.isBlank(ssavefile)) {
saveFile = defaultSaveFile;
} else {
saveFile = new File(ssavefile);
}
saveFile = new File(saveFile, name + ".fmv");
saveFile.getParentFile().mkdirs();
// format
final String defaultFormat = "mp4";
printStream.print("Format: [" + defaultFormat + "] ");
String format = scanner.nextLine();
if (StringUtils.isBlank(format)) {
format = defaultFormat;
}
// size
final Size defaultSize = Size.HD720;
printStream.print("Size: [" + defaultSize + "] ");
Size size = null;
while (size == null) {
String ssize = scanner.nextLine();
if (StringUtils.isBlank(ssize)) {
size = defaultSize;
} else {
try {
size = Size.parse(ssize);
} catch (IllegalArgumentException e) {
printStream.println("Don't understand: " + ssize);
}
}
}
// rate
final FrameRate defaultRate = FrameRate.valueOf(30, 1);
printStream.print("Rate: [" + defaultRate + "] ");
FrameRate frameRate = null;
while (frameRate == null) {
String srate = scanner.nextLine();
if (StringUtils.isBlank(srate)) {
frameRate = defaultRate;
} else {
try {
frameRate = FrameRate.parse(srate);
} catch (IllegalArgumentException e) {
printStream.println("Don't understand: " + srate);
}
}
}
OutputInfos outputInfos = new OutputInfos();
outputInfos.setSize(size);
outputInfos.setFrameRate(frameRate);
// TODO
outputInfos.setAudioSampling(44100);
outputInfos.setFormat(format);
Project project = new Project(saveFile, outputInfos);
project.setName(name);
try {
project.save();
} catch (IOException e) {
throw new RuntimeException(e);
}
return project;
}
}
use of org.fagu.fmv.utils.io.UnclosedInputStream in project fmv by f-agu.
the class Bootstrap method loadProject.
/**
* @param printStream
* @return
*/
private static Project loadProject(PrintStream printStream) {
try (Scanner scanner = new Scanner(new UnclosedInputStream(System.in))) {
printStream.println("SaveFile: ");
String ssavefile = scanner.nextLine();
File saveFile = new File(ssavefile);
return loadProject(saveFile);
}
}
use of org.fagu.fmv.utils.io.UnclosedInputStream in project fmv by f-agu.
the class Organizer method select.
/**
* @param list
* @param mainTitle
* @param titleSupplier
* @return
*/
private <O> O select(List<O> list, String mainTitle, Function<O, String> titleSupplier) {
O o = null;
if (list.isEmpty()) {
throw new RuntimeException("Never append ! (" + mainTitle + ')');
}
int size = list.size();
if (size == 1) {
o = list.get(0);
System.out.println();
System.out.println(mainTitle + " " + titleSupplier.apply(o));
System.out.println();
} else {
System.out.println();
System.out.println();
System.out.println(mainTitle);
System.out.println();
for (int i = 0; i < size; i++) {
O obj = list.get(i);
System.out.println(" " + (i + 1) + ". " + titleSupplier.apply(obj));
}
System.out.println();
int choice = -1;
try (Scanner scanner = new Scanner(new UnclosedInputStream(System.in))) {
while (choice < 0 || choice >= size) {
System.out.print("? ");
choice = scanner.nextInt() - 1;
}
}
o = list.get(choice);
}
return o;
}
Aggregations