use of com.kotcrab.vis.ui.widget.file.FileChooser in project Eidolons by IDemiurge.
the class FileChooserX method initFileChooser.
private static void initFileChooser(Stage stage, String folder, String format) {
// FileChooser.setFavoritesPrefsName("com.your.package.here.filechooser");
FileChooser fileChooser = map.get(stage);
if (!folder.contains(PathFinder.getRootPath())) {
folder = PathFinder.getRootPath() + folder;
}
Gdx.input.setInputProcessor(stage);
if (fileChooser == null) {
fileChooser = new FileChooser(FileChooser.Mode.OPEN);
if (stage instanceof GenericGuiStage) {
((GenericGuiStage) stage).setFileChooser(fileChooser);
}
stage.addActor(fileChooser.fadeIn());
map.put(stage, fileChooser);
if (format != null)
fileChooser.setFileFilter(new OrFileFilter(DirectoryFileFilter.DIRECTORY, new SuffixFileFilter("." + format)));
} else {
stage.addActor(fileChooser.fadeIn());
}
fileChooser.setDirectory(folder);
fileChooser.setSize(GdxMaster.getWidth() * 3 / 4, GdxMaster.getHeight() * 3 / 5);
GdxMaster.center(fileChooser);
fileChooser.setSelectionMode(FileChooser.SelectionMode.FILES);
FileChooser finalFileChooser = fileChooser;
FileChooserAdapter adapter;
fileChooser.clearListeners();
fileChooser.setListener(adapter = new FileChooserAdapter() {
@Override
public void canceled() {
super.canceled();
WaitMaster.receiveInput(waitOperation, null);
finalFileChooser.fadeOut();
}
@Override
public void selected(Array<FileHandle> file) {
if (file.size == 0)
return;
WaitMaster.receiveInput(waitOperation, file.get(0).file().getAbsolutePath());
finalFileChooser.fadeOut();
}
});
FileChooser finalFileChooser1 = fileChooser;
fileChooser.addListener(new InputListener() {
@Override
public boolean keyDown(InputEvent event, int keycode) {
if (keycode == Input.Keys.ENTER) {
try {
Method selectionFinished = FileChooser.class.getDeclaredMethod("selectionFinished");
selectionFinished.setAccessible(true);
try {
selectionFinished.invoke(finalFileChooser1);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
if (keycode == Input.Keys.ESCAPE) {
finalFileChooser1.fadeOut();
adapter.canceled();
}
return true;
}
});
}
Aggregations