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);
}
Aggregations