Search in sources :

Example 1 with FileChooser

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

the class LibgdxGraphScreen method exportShader.

private void exportShader() {
    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");
            }
            writeGraph(selectedFile, ((GraphDesignTab) tabbedPane.getActiveTab()).serializeGraph());
        }
    });
    getStage().addActor(fileChooser.fadeIn());
}
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 2 with FileChooser

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

the class LibgdxGraphScreen method saveAs.

private void saveAs() {
    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());
}
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 3 with FileChooser

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

the class LibgdxGraphScreen method open.

private void open() {
    if (graphDesignTab != null && graphDesignTab.isDirty()) {
        Dialogs.showErrorDialog(getStage(), "Current pipeline has been modified, close it or save it");
    } else {
        removeAllTabs();
        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);
                loadPipelineFromFile(selectedFile);
                editedFile = selectedFile;
                graphDesignTab.setDirty(false);
            }
        });
        getStage().addActor(fileChooser.fadeIn());
    }
}
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 4 with FileChooser

use of com.kotcrab.vis.ui.widget.file.FileChooser in project Mundus by jpooleycodes.

the class FileChooserField method setupListeners.

private void setupListeners() {
    fcBtn.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            FileChooser fileChooser = UI.INSTANCE.getFileChooser();
            fileChooser.setSelectionMode(mode);
            fileChooser.setListener(new SingleFileChooserListener() {

                @Override
                protected void selected(FileHandle file) {
                    fileHandle = file;
                    path = file.path();
                    textField.setText(file.path());
                    if (fileSelected != null) {
                        fileSelected.selected(file);
                    }
                }
            });
            UI.INSTANCE.addActor(fileChooser.fadeIn());
        }
    });
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) FileChooser(com.kotcrab.vis.ui.widget.file.FileChooser) SingleFileChooserListener(com.kotcrab.vis.ui.widget.file.SingleFileChooserListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 5 with FileChooser

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

the class AssetsList method create.

private void create() {
    final String type = assetTypes.getSelected();
    if (type.equals("atlases")) {
        new CreateAtlasDialog(skin).show(getStage());
    // addAssets();
    } else if (type.equals("particles")) {
        // Open the particle editor
        List<String> cp = new ArrayList<String>();
        cp.add(System.getProperty("java.class.path"));
        try {
            RunProccess.runJavaProccess("com.badlogic.gdx.tools.particleeditor.ParticleEditor", cp, null);
        } catch (IOException e) {
            Message.showMsgDialog(getStage(), "Error", "Error launching Particle Editor.");
            EditorLogger.printStackTrace(e);
        }
    } else {
        FileChooser fileChooser = new FileChooser(Mode.OPEN);
        fileChooser.setSelectionMode(SelectionMode.FILES);
        fileChooser.setMultiSelectionEnabled(true);
        fileChooser.setSize(Gdx.graphics.getWidth() * 0.7f, Gdx.graphics.getHeight() * 0.7f);
        fileChooser.setViewMode(ViewMode.LIST);
        getStage().addActor(fileChooser);
        if (lastDir != null)
            fileChooser.setDirectory(lastDir);
        // chooser.setTitle("Select the '" + type + "' asset files");
        // allow "All Types" mode where all files are shown
        FileTypeFilter typeFilter = new FileTypeFilter(true);
        switch(type) {
            case "images":
                typeFilter.addRule("Images (*.png, *.jpg, *.etc1)", "jpg", "png", "etc1");
                break;
            case "music":
            case "sounds":
            case "voices":
                typeFilter.addRule("Sound (*.mp3, *.wav, *.ogg)", "wav", "mp3", "ogg");
                break;
            case "spine":
                typeFilter.addRule("Spine (*.skel, *.json)", "skel", "json");
                break;
            default:
                typeFilter.addRule("All", "");
                break;
        }
        fileChooser.setFileTypeFilter(typeFilter);
        fileChooser.setListener(new FileChooserListener() {

            @Override
            public void selected(Array<FileHandle> files) {
                try {
                    String dirName = getAssetDir(type);
                    lastDir = files.get(0).parent().file();
                    // Si no existe la carpeta la creamos
                    File dir = new File(dirName);
                    if (!dir.exists())
                        dir.mkdir();
                    for (FileHandle f : files) {
                        if (type.equals("images")) {
                            List<String> res = Ctx.project.getResolutions();
                            for (String r : res) {
                                File destFile = new File(dirName + "/" + r + "/" + f.file().getName());
                                float scale = Float.parseFloat(r);
                                if (scale != 1.0f) {
                                    ImageUtils.scaleImageFile(f.file(), destFile, scale);
                                } else {
                                    Files.copy(f.file().toPath(), destFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
                                }
                            }
                        } else {
                            File destFile = new File(dir, f.file().getName());
                            Files.copy(f.file().toPath(), destFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
                        }
                    }
                    addAssets();
                } catch (Exception ex) {
                    String msg = "Something went wrong while getting the assets.\n\n" + ex.getClass().getSimpleName() + " - " + ex.getMessage();
                    Message.showMsgDialog(getStage(), "Error", msg);
                    EditorLogger.printStackTrace(ex);
                }
            }

            @Override
            public void canceled() {
            }
        });
    }
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) FileTypeFilter(com.kotcrab.vis.ui.widget.file.FileTypeFilter) IOException(java.io.IOException) IOException(java.io.IOException) Array(com.badlogic.gdx.utils.Array) FileChooserListener(com.kotcrab.vis.ui.widget.file.FileChooserListener) FileChooser(com.kotcrab.vis.ui.widget.file.FileChooser) ArrayList(java.util.ArrayList) CustomList(com.bladecoder.engineeditor.ui.panels.CustomList) List(java.util.List) File(java.io.File)

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