Search in sources :

Example 16 with FileChooserAdapter

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());
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) FileChooser(com.kotcrab.vis.ui.widget.file.FileChooser) FileTypeFilter(com.kotcrab.vis.ui.widget.file.FileTypeFilter) FileChooserAdapter(com.kotcrab.vis.ui.widget.file.FileChooserAdapter)

Example 17 with FileChooserAdapter

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());
}
Also used : InputStreamReader(java.io.InputStreamReader) FileHandle(com.badlogic.gdx.files.FileHandle) InputStream(java.io.InputStream) FileChooser(com.kotcrab.vis.ui.widget.file.FileChooser) JsonValue(com.badlogic.gdx.utils.JsonValue) FileChooserAdapter(com.kotcrab.vis.ui.widget.file.FileChooserAdapter) JsonReader(com.badlogic.gdx.utils.JsonReader) IOException(java.io.IOException)

Example 18 with FileChooserAdapter

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;
        }
    });
}
Also used : OrFileFilter(org.apache.commons.io.filefilter.OrFileFilter) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) Array(com.badlogic.gdx.utils.Array) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) GenericGuiStage(libgdx.stage.GenericGuiStage) FileChooser(com.kotcrab.vis.ui.widget.file.FileChooser) FileChooserAdapter(com.kotcrab.vis.ui.widget.file.FileChooserAdapter) SuffixFileFilter(org.apache.commons.io.filefilter.SuffixFileFilter) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent)

Aggregations

FileChooserAdapter (com.kotcrab.vis.ui.widget.file.FileChooserAdapter)18 FileHandle (com.badlogic.gdx.files.FileHandle)16 FileChooser (com.kotcrab.vis.ui.widget.file.FileChooser)9 Array (com.badlogic.gdx.utils.Array)5 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)4 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)4 File (java.io.File)3 FileFilter (java.io.FileFilter)3 IProject (com.talosvfx.talos.editor.project.IProject)2 Pixmap (com.badlogic.gdx.graphics.Pixmap)1 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)1 JsonReader (com.badlogic.gdx.utils.JsonReader)1 JsonValue (com.badlogic.gdx.utils.JsonValue)1 Menu (com.kotcrab.vis.ui.widget.Menu)1 MenuItem (com.kotcrab.vis.ui.widget.MenuItem)1 FileTypeFilter (com.kotcrab.vis.ui.widget.file.FileTypeFilter)1 ShaderNodeStage (com.talosvfx.talos.editor.addons.shader.workspace.ShaderNodeStage)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1