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