Search in sources :

Example 6 with FileNameExtensionFilter

use of com.revolsys.io.file.FileNameExtensionFilter in project com.revolsys.open by revolsys.

the class ProjectFrame method actionOpenProject.

private void actionOpenProject() {
    if (this.project != null && this.project.saveWithPrompt()) {
        final JFileChooser fileChooser = SwingUtil.newFileChooser("Open Project", this.preferences, PREFERENCE_PROJECT_DIRECTORY);
        final FileNameExtensionFilter filter = new FileNameExtensionFilter("Project (*.rgmap)", "rgmap");
        fileChooser.setAcceptAllFileFilterUsed(true);
        fileChooser.addChoosableFileFilter(filter);
        fileChooser.setFileFilter(filter);
        if (!OS.isMac()) {
            fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        }
        final int returnVal = fileChooser.showOpenDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            final File projectDirectory = fileChooser.getSelectedFile();
            final File parentDirectory = projectDirectory.getParentFile();
            this.preferences.setValue(PREFERENCE_PROJECT_DIRECTORY, parentDirectory);
            openProject(projectDirectory.toPath());
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) FileNameExtensionFilter(com.revolsys.io.file.FileNameExtensionFilter) File(java.io.File)

Example 7 with FileNameExtensionFilter

use of com.revolsys.io.file.FileNameExtensionFilter in project com.revolsys.open by revolsys.

the class ScriptRunner method runScript.

public static void runScript(final Window window, final Consumer<File> action) {
    final JFileChooser fileChooser = SwingUtil.newFileChooser("Select Script", "com.revolsys.swing.tools.script", "directory");
    final FileNameExtensionFilter groovyFilter = new FileNameExtensionFilter("Groovy Script", "groovy");
    fileChooser.addChoosableFileFilter(groovyFilter);
    final FileNameExtensionFilter javaFilter = new FileNameExtensionFilter("Java", "java");
    fileChooser.addChoosableFileFilter(javaFilter);
    fileChooser.setMultiSelectionEnabled(false);
    final int returnVal = fileChooser.showOpenDialog(window);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        final File selectedFile = fileChooser.getSelectedFile();
        final File scriptFile = FileUtil.getFile(selectedFile);
        PreferencesUtil.setUserString("com.revolsys.swing.tools.script", "directory", scriptFile.getParent());
        action.accept(scriptFile);
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) FileNameExtensionFilter(com.revolsys.io.file.FileNameExtensionFilter) File(java.io.File)

Example 8 with FileNameExtensionFilter

use of com.revolsys.io.file.FileNameExtensionFilter in project com.revolsys.open by revolsys.

the class LayerGroup method actionOpenFileLayer.

private void actionOpenFileLayer() {
    final Window window = SwingUtil.getActiveWindow();
    final JFileChooser fileChooser = SwingUtil.newFileChooser(getClass(), "currentDirectory");
    fileChooser.setMultiSelectionEnabled(true);
    final Set<String> allImageExtensions = new TreeSet<>();
    final List<FileNameExtensionFilter> imageFileFilters = IoFactory.newFileFilters(allImageExtensions, GeoreferencedImageReadFactory.class);
    final Set<String> allRecordExtensions = new TreeSet<>();
    final List<FileNameExtensionFilter> recordFileFilters = IoFactory.newFileFilters(allRecordExtensions, RecordReaderFactory.class);
    final Set<String> allElevationModelExtensions = new TreeSet<>();
    final List<FileNameExtensionFilter> elevationModelFileFilters = IoFactory.newFileFilters(allElevationModelExtensions, GriddedElevationModelReadFactory.class);
    final Set<String> allTinExtensions = new TreeSet<>();
    final List<FileNameExtensionFilter> tinFileFilters = IoFactory.newFileFilters(allTinExtensions, GriddedElevationModelReadFactory.class);
    final Set<String> allExtensions = new TreeSet<>();
    allExtensions.addAll(allRecordExtensions);
    allExtensions.addAll(allImageExtensions);
    allExtensions.addAll(allElevationModelExtensions);
    allExtensions.addAll(allTinExtensions);
    final FileNameExtensionFilter allFilter = IoFactory.newFileFilter("All Supported Files", allExtensions);
    fileChooser.addChoosableFileFilter(allFilter);
    fileChooser.addChoosableFileFilter(IoFactory.newFileFilter("All Vector/Record Files", allRecordExtensions));
    fileChooser.addChoosableFileFilter(IoFactory.newFileFilter("All Image Files", allImageExtensions));
    fileChooser.addChoosableFileFilter(IoFactory.newFileFilter("All Gridded Elevation Model Files", allElevationModelExtensions));
    fileChooser.addChoosableFileFilter(IoFactory.newFileFilter("All Triangulated Irregular Network Files", allTinExtensions));
    for (final List<? extends FileFilter> filters : Arrays.asList(recordFileFilters, imageFileFilters, elevationModelFileFilters, tinFileFilters)) {
        for (final FileFilter fileFilter : filters) {
            fileChooser.addChoosableFileFilter(fileFilter);
        }
    }
    fileChooser.setAcceptAllFileFilterUsed(false);
    fileChooser.setFileFilter(allFilter);
    final int status = fileChooser.showDialog(window, "Open Files");
    if (status == JFileChooser.APPROVE_OPTION) {
        final Object menuSource = MenuFactory.getMenuSource();
        final LayerGroup layerGroup;
        if (menuSource instanceof LayerGroupTreeNode) {
            final LayerGroupTreeNode node = (LayerGroupTreeNode) menuSource;
            layerGroup = node.getGroup();
        } else if (menuSource instanceof LayerGroup) {
            layerGroup = (LayerGroup) menuSource;
        } else {
            layerGroup = Project.get();
        }
        for (final File file : fileChooser.getSelectedFiles()) {
            Invoke.background("Open file: " + FileUtil.getCanonicalPath(file), () -> layerGroup.openFile(file));
        }
    }
    SwingUtil.saveFileChooserDirectory(getClass(), "currentDirectory", fileChooser);
}
Also used : Window(java.awt.Window) LayerGroupTreeNode(com.revolsys.swing.tree.node.layer.LayerGroupTreeNode) FileNameExtensionFilter(com.revolsys.io.file.FileNameExtensionFilter) JFileChooser(javax.swing.JFileChooser) TreeSet(java.util.TreeSet) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File)

Example 9 with FileNameExtensionFilter

use of com.revolsys.io.file.FileNameExtensionFilter in project com.revolsys.open by revolsys.

the class ConnectionManagerTrees method exportConnection.

protected static void exportConnection(final Connection connection) {
    final ConnectionRegistry<?> connectionRegistry = connection.getRegistry();
    String connectionType = connectionRegistry.getConnectionManager().getName();
    if (connectionType.endsWith("s")) {
        connectionType = connectionType.substring(0, connectionType.length() - 1);
    }
    if (!connectionType.endsWith(" Connection")) {
        connectionType += " Connection";
    }
    final Window window = SwingUtil.getActiveWindow();
    final Class<?> chooserClass = connectionRegistry.getClass();
    final JFileChooser fileChooser = SwingUtil.newFileChooser(chooserClass, "currentDirectory");
    fileChooser.setDialogTitle("Export " + connectionType);
    fileChooser.setMultiSelectionEnabled(false);
    final String fileExtension = connectionRegistry.getFileExtension();
    final FileNameExtensionFilter allFilter = new FileNameExtensionFilter("*." + fileExtension, fileExtension);
    fileChooser.addChoosableFileFilter(allFilter);
    fileChooser.setAcceptAllFileFilterUsed(false);
    fileChooser.setFileFilter(allFilter);
    final String connectionName = connection.getName();
    fileChooser.setSelectedFile(new File(fileChooser.getCurrentDirectory(), connectionName + "." + fileExtension));
    final int status = fileChooser.showSaveDialog(window);
    if (status == JFileChooser.APPROVE_OPTION) {
        Invoke.background("Export " + connectionType, () -> {
            File file = fileChooser.getSelectedFile();
            file = FileUtil.getFileWithExtension(file, fileExtension);
            connection.writeToFile(file);
        });
    }
    SwingUtil.saveFileChooserDirectory(chooserClass, "currentDirectory", fileChooser);
}
Also used : Window(java.awt.Window) JFileChooser(javax.swing.JFileChooser) FileNameExtensionFilter(com.revolsys.io.file.FileNameExtensionFilter) File(java.io.File)

Example 10 with FileNameExtensionFilter

use of com.revolsys.io.file.FileNameExtensionFilter in project com.revolsys.open by revolsys.

the class ConnectionManagerTrees method importConnection.

protected static void importConnection(final ConnectionRegistry<? extends Connection> connectionRegistry) {
    String name = connectionRegistry.getConnectionManager().getName();
    if (name.endsWith("s")) {
        name = name.substring(0, name.length() - 1);
    }
    if (!name.endsWith(" Connection")) {
        name += " Connection";
    }
    final Window window = SwingUtil.getActiveWindow();
    final Class<?> chooserClass = connectionRegistry.getClass();
    final JFileChooser fileChooser = SwingUtil.newFileChooser(chooserClass, "currentDirectory");
    fileChooser.setDialogTitle("Import " + name);
    fileChooser.setMultiSelectionEnabled(true);
    final String fileExtension = connectionRegistry.getFileExtension();
    final FileNameExtensionFilter allFilter = new FileNameExtensionFilter("*." + fileExtension, fileExtension);
    fileChooser.addChoosableFileFilter(allFilter);
    fileChooser.setAcceptAllFileFilterUsed(false);
    fileChooser.setFileFilter(allFilter);
    final int status = fileChooser.showDialog(window, "Import");
    if (status == JFileChooser.APPROVE_OPTION) {
        Invoke.background("Import " + name, () -> {
            for (final File file : fileChooser.getSelectedFiles()) {
                final Path path = file.toPath();
                connectionRegistry.importConnection(path);
            }
        });
    }
    SwingUtil.saveFileChooserDirectory(chooserClass, "currentDirectory", fileChooser);
}
Also used : Window(java.awt.Window) Path(java.nio.file.Path) JFileChooser(javax.swing.JFileChooser) FileNameExtensionFilter(com.revolsys.io.file.FileNameExtensionFilter) File(java.io.File)

Aggregations

FileNameExtensionFilter (com.revolsys.io.file.FileNameExtensionFilter)10 File (java.io.File)8 JFileChooser (javax.swing.JFileChooser)8 Window (java.awt.Window)4 PathResource (com.revolsys.spring.resource.PathResource)2 ArrayList (java.util.ArrayList)2 LayerGroupTreeNode (com.revolsys.swing.tree.node.layer.LayerGroupTreeNode)1 Path (java.nio.file.Path)1 TreeSet (java.util.TreeSet)1 FileFilter (javax.swing.filechooser.FileFilter)1