use of com.kotcrab.vis.ui.widget.file.FileChooserAdapter in project gdx-graph by MarcinSc.
the class PluginsDialog method addPlugin.
private void addPlugin() {
FileTypeFilter filter = new FileTypeFilter(true);
filter.addRule("Plugin File (*.jar, *.json)", "jar", "json");
FileChooser fileChooser = new FileChooser(FileChooser.Mode.OPEN);
fileChooser.setModal(true);
fileChooser.setSelectionMode(FileChooser.SelectionMode.FILES);
fileChooser.setFileTypeFilter(filter);
fileChooser.setListener(new FileChooserAdapter() {
@Override
public void selected(Array<FileHandle> file) {
FileHandle selectedFile = file.get(0);
processPlugin(selectedFile);
}
});
getStage().addActor(fileChooser.fadeIn());
}
use of com.kotcrab.vis.ui.widget.file.FileChooserAdapter in project gdx-graph by MarcinSc.
the class LoadFileGraphShaderTemplate method invokeTemplate.
@Override
public void invokeTemplate(Stage stage, final Callback callback) {
FileChooser fileChooser = new FileChooser(FileChooser.Mode.OPEN);
fileChooser.setModal(true);
fileChooser.setSelectionMode(FileChooser.SelectionMode.FILES);
fileChooser.setListener(new FileChooserAdapter() {
@Override
public void selected(Array<FileHandle> file) {
FileHandle selectedFile = file.get(0);
JsonReader parser = new JsonReader();
try {
InputStream is = selectedFile.read();
try {
JsonValue shader = parser.parse(new InputStreamReader(is));
callback.addShader(selectedFile.nameWithoutExtension(), shader);
} finally {
is.close();
}
} catch (IOException exp) {
// Ignored
}
}
});
stage.addActor(fileChooser.fadeIn());
}
use of com.kotcrab.vis.ui.widget.file.FileChooserAdapter 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