Search in sources :

Example 11 with PathResource

use of com.revolsys.spring.resource.PathResource in project com.revolsys.open by revolsys.

the class LayerGroup method actionImportProject.

public void actionImportProject(final String title, final boolean resetProject) {
    final Project project = getProject();
    if (resetProject) {
        if (!project.saveWithPrompt()) {
            return;
        }
    }
    final JFileChooser fileChooser = SwingUtil.newFileChooser(title, "com.revolsys.swing.map.project", "templateDirectory");
    final FileNameExtensionFilter filter = new FileNameExtensionFilter("Project (*.rgmap)", "rgmap");
    fileChooser.setAcceptAllFileFilterUsed(true);
    fileChooser.addChoosableFileFilter(filter);
    fileChooser.setFileFilter(filter);
    if (OS.isMac()) {
        fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    } else {
        fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    }
    final Window window = SwingUtil.getActiveWindow();
    final int returnVal = fileChooser.showOpenDialog(window);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        final File projectDirectory = fileChooser.getSelectedFile();
        if (projectDirectory != null) {
            PreferencesUtil.setUserString("com.revolsys.swing.map.project", "templateDirectory", projectDirectory.getParent());
            final PathResource resource = new PathResource(projectDirectory);
            importProject(project, resource, resetProject);
        }
    }
}
Also used : Window(java.awt.Window) JFileChooser(javax.swing.JFileChooser) PathResource(com.revolsys.spring.resource.PathResource) FileNameExtensionFilter(com.revolsys.io.file.FileNameExtensionFilter) File(java.io.File)

Example 12 with PathResource

use of com.revolsys.spring.resource.PathResource in project com.revolsys.open by revolsys.

the class Project method getSaveAsDirectory.

public Path getSaveAsDirectory() {
    File directory = null;
    final JFileChooser fileChooser = SwingUtil.newFileChooser("Save Project", "com.revolsys.swing.map.project", "directory");
    fileChooser.setFileFilter(new FileNameExtensionFilter("Project", "rgmap"));
    fileChooser.setMultiSelectionEnabled(false);
    final int returnVal = fileChooser.showSaveDialog(SwingUtil.getActiveWindow());
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        directory = fileChooser.getSelectedFile();
        final String fileExtension = FileUtil.getFileNameExtension(directory);
        if (!"rgmap".equals(fileExtension)) {
            directory = new File(directory.getParentFile(), directory.getName() + ".rgmap");
        }
        PreferencesUtil.setUserString("com.revolsys.swing.map.project", "directory", directory.getParent());
        if (directory.exists()) {
            FileUtil.deleteDirectory(directory);
        }
        directory.mkdirs();
        this.resource = new PathResource(directory);
        return directory.toPath();
    } else {
        return null;
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) PathResource(com.revolsys.spring.resource.PathResource) FileNameExtensionFilter(com.revolsys.io.file.FileNameExtensionFilter) File(java.io.File)

Example 13 with PathResource

use of com.revolsys.spring.resource.PathResource in project com.revolsys.open by revolsys.

the class FileUtil method getFile.

public static File getFile(final Resource resource) {
    if (resource instanceof PathResource) {
        final PathResource fileResource = (PathResource) resource;
        return fileResource.getFile();
    } else {
        final String fileName = resource.getFilename();
        final String ext = getFileNameExtension(fileName);
        final File file = newTempFile(fileName, "." + ext);
        copy(resource.getInputStream(), file);
        file.deleteOnExit();
        return file;
    }
}
Also used : PathResource(com.revolsys.spring.resource.PathResource) File(java.io.File)

Example 14 with PathResource

use of com.revolsys.spring.resource.PathResource in project com.revolsys.open by revolsys.

the class AbstractConnectionRegistry method setDirectory.

protected void setDirectory(final Resource directoryResource) {
    if (directoryResource instanceof PathResource) {
        final PathResource pathResource = (PathResource) directoryResource;
        final Path directory = pathResource.getPath();
        boolean readOnly = isReadOnly();
        if (!readOnly) {
            if (directoryResource.exists()) {
                readOnly = !Files.isWritable(directory);
            } else if (Paths.deleteDirectories(directory)) {
                readOnly = false;
            } else {
                readOnly = true;
            }
        }
        setReadOnly(readOnly);
        this.directory = directory;
    } else {
        setReadOnly(true);
        this.directory = null;
    }
}
Also used : Path(java.nio.file.Path) PathResource(com.revolsys.spring.resource.PathResource)

Example 15 with PathResource

use of com.revolsys.spring.resource.PathResource in project com.revolsys.open by revolsys.

the class MoepDirectoryReader method setDirectory.

@Override
public void setDirectory(final File directory) {
    super.setDirectory(directory);
    final String name = FileUtil.getFileName(directory);
    final File file = new File(directory, name + "s.bin");
    final Reader<Record> supDataReader = newReader(new PathResource(file));
    for (final Record supData : supDataReader) {
        final String featureCode = supData.getValue(MoepConstants.FEATURE_CODE);
        if (featureCode.equals("KN00020000")) {
            final String text = supData.getValue(MoepConstants.TEXT);
            final String[] versionFields = text.split(" ");
            final String dateString = versionFields[2];
            this.submissionDate = new Date(Dates.getDate("yyyyMMdd", dateString).getTime());
            this.revisionKey = versionFields[3];
            this.integrationDate = new Date(Dates.getDate("yyyyMMdd", versionFields[4]).getTime());
            this.specificationsRelease = versionFields[5];
        }
    }
}
Also used : PathResource(com.revolsys.spring.resource.PathResource) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord) File(java.io.File) Date(java.sql.Date)

Aggregations

PathResource (com.revolsys.spring.resource.PathResource)24 File (java.io.File)15 Resource (com.revolsys.spring.resource.Resource)7 Record (com.revolsys.record.Record)4 RecordDefinition (com.revolsys.record.schema.RecordDefinition)4 Geometry (com.revolsys.geometry.model.Geometry)3 ArrayRecord (com.revolsys.record.ArrayRecord)3 FileNameExtensionFilter (com.revolsys.io.file.FileNameExtensionFilter)2 RecordWriter (com.revolsys.record.io.RecordWriter)2 Path (java.nio.file.Path)2 JFileChooser (javax.swing.JFileChooser)2 LasPointCloud (com.revolsys.elevation.cloud.las.LasPointCloud)1 TriangulatedIrregularNetwork (com.revolsys.elevation.tin.TriangulatedIrregularNetwork)1 BoundingBox (com.revolsys.geometry.model.BoundingBox)1 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)1 AbstractRecordWriter (com.revolsys.io.AbstractRecordWriter)1 PathName (com.revolsys.io.PathName)1 ExtensionFilenameFilter (com.revolsys.io.filter.ExtensionFilenameFilter)1 ObjectWithProperties (com.revolsys.properties.ObjectWithProperties)1 RecordWriterFactory (com.revolsys.record.io.RecordWriterFactory)1