Search in sources :

Example 11 with FileChooser

use of com.kotcrab.vis.ui.widget.file.FileChooser in project bladecoder-adventure-engine by bladecoder.

the class ToolsWindow method exportUIImages.

protected void exportUIImages() {
    FileChooser fileChooser = new FileChooser(Mode.OPEN);
    fileChooser.setSize(Gdx.graphics.getWidth() * 0.7f, Gdx.graphics.getHeight() * 0.7f);
    fileChooser.setViewMode(ViewMode.LIST);
    fileChooser.setSelectionMode(SelectionMode.DIRECTORIES);
    getStage().addActor(fileChooser);
    fileChooser.setListener(new FileChooserListener() {

        @Override
        public void selected(Array<FileHandle> files) {
            try {
                // fileChooser.setTitle("Select the file to export the
                // project texts");
                ImageUtils.unpackAtlas(new File(Ctx.project.getAssetPath() + Project.UI_PATH + "/1/ui.atlas"), files.get(0).file());
                Message.showMsg(getStage(), "UI Atlas images exported sucessfully.", 4);
            } catch (Exception e) {
                Message.showMsg(getStage(), "There was a problem exporting images from UI Atlas.", 4);
                EditorLogger.printStackTrace(e);
            }
        }

        @Override
        public void canceled() {
        }
    });
}
Also used : FileChooserListener(com.kotcrab.vis.ui.widget.file.FileChooserListener) FileHandle(com.badlogic.gdx.files.FileHandle) FileChooser(com.kotcrab.vis.ui.widget.file.FileChooser) File(java.io.File) IOException(java.io.IOException)

Example 12 with FileChooser

use of com.kotcrab.vis.ui.widget.file.FileChooser in project bladecoder-adventure-engine by bladecoder.

the class ToolsWindow method importTSV.

private void importTSV() {
    FileChooser fileChooser = new FileChooser(Mode.OPEN);
    fileChooser.setSize(Gdx.graphics.getWidth() * 0.7f, Gdx.graphics.getHeight() * 0.7f);
    fileChooser.setViewMode(ViewMode.LIST);
    fileChooser.setSelectionMode(SelectionMode.FILES);
    getStage().addActor(fileChooser);
    fileChooser.setListener(new FileChooserListener() {

        @Override
        public void selected(Array<FileHandle> files) {
            try {
                // chooser.setTitle("Select the .tsv file to import");
                I18NUtils.importTSV(Ctx.project.getAssetPath() + Project.MODEL_PATH, files.get(0).file().getAbsolutePath(), Ctx.project.getChapter().getId(), "default");
                // Reload texts
                Ctx.project.getI18N().load(Ctx.project.getChapter().getId());
                Message.showMsg(getStage(), files.get(0).file().getName() + " imported sucessfully.", 4);
            } catch (IOException e) {
                Message.showMsg(getStage(), "There was a problem importing the .tsv file.", 4);
                EditorLogger.printStackTrace(e);
            }
        }

        @Override
        public void canceled() {
        }
    });
}
Also used : FileChooserListener(com.kotcrab.vis.ui.widget.file.FileChooserListener) FileHandle(com.badlogic.gdx.files.FileHandle) FileChooser(com.kotcrab.vis.ui.widget.file.FileChooser) IOException(java.io.IOException)

Example 13 with FileChooser

use of com.kotcrab.vis.ui.widget.file.FileChooser in project gdx-graph by MarcinSc.

the class LibgdxGraphScreen method save.

private void save() {
    if (graphDesignTab != null) {
        if (editedFile == null) {
            FileChooser fileChooser = new FileChooser(FileChooser.Mode.SAVE);
            fileChooser.setModal(true);
            fileChooser.setSelectionMode(FileChooser.SelectionMode.FILES);
            fileChooser.setListener(new FileChooserAdapter() {

                @Override
                public void selected(Array<FileHandle> file) {
                    FileHandle selectedFile = file.get(0);
                    if (!selectedFile.name().toLowerCase().endsWith(".json")) {
                        selectedFile = selectedFile.parent().child(selectedFile.name() + ".json");
                    }
                    editedFile = selectedFile;
                    saveToFile(graphDesignTab, selectedFile);
                }
            });
            getStage().addActor(fileChooser.fadeIn());
        } else {
            saveToFile(graphDesignTab, editedFile);
        }
    }
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) FileChooser(com.kotcrab.vis.ui.widget.file.FileChooser) FileChooserAdapter(com.kotcrab.vis.ui.widget.file.FileChooserAdapter)

Example 14 with FileChooser

use of com.kotcrab.vis.ui.widget.file.FileChooser 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 15 with FileChooser

use of com.kotcrab.vis.ui.widget.file.FileChooser 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)

Aggregations

FileChooser (com.kotcrab.vis.ui.widget.file.FileChooser)16 FileHandle (com.badlogic.gdx.files.FileHandle)14 FileChooserAdapter (com.kotcrab.vis.ui.widget.file.FileChooserAdapter)9 IOException (java.io.IOException)6 FileChooserListener (com.kotcrab.vis.ui.widget.file.FileChooserListener)5 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)3 Array (com.badlogic.gdx.utils.Array)3 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)2 FileTypeFilter (com.kotcrab.vis.ui.widget.file.FileTypeFilter)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)1 JsonReader (com.badlogic.gdx.utils.JsonReader)1 JsonValue (com.badlogic.gdx.utils.JsonValue)1 CustomList (com.bladecoder.engineeditor.ui.panels.CustomList)1 SingleFileChooserListener (com.kotcrab.vis.ui.widget.file.SingleFileChooserListener)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1