Search in sources :

Example 1 with FileTypeFilter

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

Example 2 with FileTypeFilter

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

Aggregations

FileHandle (com.badlogic.gdx.files.FileHandle)2 FileChooser (com.kotcrab.vis.ui.widget.file.FileChooser)2 FileTypeFilter (com.kotcrab.vis.ui.widget.file.FileTypeFilter)2 Array (com.badlogic.gdx.utils.Array)1 CustomList (com.bladecoder.engineeditor.ui.panels.CustomList)1 FileChooserAdapter (com.kotcrab.vis.ui.widget.file.FileChooserAdapter)1 FileChooserListener (com.kotcrab.vis.ui.widget.file.FileChooserListener)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1