Search in sources :

Example 1 with LayerGroupTreeNode

use of com.revolsys.swing.tree.node.layer.LayerGroupTreeNode 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)

Aggregations

FileNameExtensionFilter (com.revolsys.io.file.FileNameExtensionFilter)1 LayerGroupTreeNode (com.revolsys.swing.tree.node.layer.LayerGroupTreeNode)1 Window (java.awt.Window)1 File (java.io.File)1 TreeSet (java.util.TreeSet)1 JFileChooser (javax.swing.JFileChooser)1 FileFilter (javax.swing.filechooser.FileFilter)1