Search in sources :

Example 1 with MostRecentFiles

use of org.gephi.desktop.mrufiles.api.MostRecentFiles in project gephi by gephi.

the class RecentFiles method getMenuPresenter.

@Override
public JMenuItem getMenuPresenter() {
    JMenu menu = new JMenu(NbBundle.getMessage(RecentFiles.class, "CTL_OpenRecentFiles"));
    MostRecentFiles mru = Lookup.getDefault().lookup(MostRecentFiles.class);
    for (String filePath : mru.getMRUFileList()) {
        final File file = new File(filePath);
        if (file.exists()) {
            final String fileName = file.getName();
            JMenuItem menuItem = new JMenuItem(new AbstractAction(fileName) {

                @Override
                public void actionPerformed(ActionEvent e) {
                    FileObject fileObject = FileUtil.toFileObject(file);
                    if (fileObject.hasExt(GEPHI_EXTENSION)) {
                        ProjectControllerUI pc = Lookup.getDefault().lookup(ProjectControllerUI.class);
                        try {
                            pc.openProject(file);
                        } catch (Exception ex) {
                            Exceptions.printStackTrace(ex);
                        }
                    } else {
                        ImportControllerUI importController = Lookup.getDefault().lookup(ImportControllerUI.class);
                        if (importController.getImportController().isFileSupported(file)) {
                            importController.importFile(fileObject);
                        }
                    }
                }
            });
            menu.add(menuItem);
        }
    }
    return menu;
}
Also used : MostRecentFiles(org.gephi.desktop.mrufiles.api.MostRecentFiles) ActionEvent(java.awt.event.ActionEvent) MostRecentFiles(org.gephi.desktop.mrufiles.api.MostRecentFiles) ImportControllerUI(org.gephi.desktop.importer.api.ImportControllerUI) FileObject(org.openide.filesystems.FileObject) JMenuItem(javax.swing.JMenuItem) File(java.io.File) AbstractAction(javax.swing.AbstractAction) JMenu(javax.swing.JMenu) ProjectControllerUI(org.gephi.desktop.project.api.ProjectControllerUI)

Example 2 with MostRecentFiles

use of org.gephi.desktop.mrufiles.api.MostRecentFiles in project gephi by gephi.

the class ProjectControllerUIImpl method loadProject.

private void loadProject(File file) {
    lockProjectActions();
    final Runnable loadTask = controller.openProject(file);
    final String fileName = file.getName();
    Runnable loadRunnable = new Runnable() {

        @Override
        public void run() {
            loadTask.run();
            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    JFrame frame = (JFrame) WindowManager.getDefault().getMainWindow();
                    String title = frame.getTitle() + " - " + fileName;
                    frame.setTitle(title);
                }
            });
            // Status line
            StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(ProjectControllerUIImpl.class, "ProjectControllerUI.status.opened", fileName));
        }
    };
    if (loadTask instanceof LongTask) {
        longTaskExecutor.execute((LongTask) loadTask, loadRunnable);
    } else {
        longTaskExecutor.execute(null, loadRunnable);
    }
    // Save MRU
    MostRecentFiles mostRecentFiles = Lookup.getDefault().lookup(MostRecentFiles.class);
    mostRecentFiles.addFile(file.getAbsolutePath());
}
Also used : MostRecentFiles(org.gephi.desktop.mrufiles.api.MostRecentFiles) LongTask(org.gephi.utils.longtask.spi.LongTask) JFrame(javax.swing.JFrame)

Example 3 with MostRecentFiles

use of org.gephi.desktop.mrufiles.api.MostRecentFiles in project gephi by gephi.

the class DesktopImportControllerUI method importFiles.

@Override
public void importFiles(FileObject[] fileObjects) {
    MostRecentFiles mostRecentFiles = Lookup.getDefault().lookup(MostRecentFiles.class);
    fileObjects = Arrays.copyOf(fileObjects, fileObjects.length);
    // Extract files if they are zipped:
    for (int i = 0; i < fileObjects.length; i++) {
        fileObjects[i] = ImportUtils.getArchivedFile(fileObjects[i]);
        if (FileUtil.isArchiveArtifact(fileObjects[i])) {
            try {
                // Copy the archived file so we never have problems converting it to a simple File during import:
                File tempDir = TempDirUtils.createTempDirectory();
                fileObjects[i] = FileUtil.copyFile(fileObjects[i], FileUtil.toFileObject(tempDir), fileObjects[i].getName());
            } catch (IOException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    }
    Reader[] readers = new Reader[fileObjects.length];
    FileImporter[] importers = new FileImporter[fileObjects.length];
    try {
        for (int i = 0; i < fileObjects.length; i++) {
            FileObject fileObject = fileObjects[i];
            importers[i] = controller.getFileImporter(fileObject);
            if (importers[i] == null) {
                NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(getClass(), "DesktopImportControllerUI.error_no_matching_file_importer"), NotifyDescriptor.WARNING_MESSAGE);
                DialogDisplayer.getDefault().notify(msg);
                return;
            }
            readers[i] = ImportUtils.getTextReader(fileObject);
            // MRU
            mostRecentFiles.addFile(fileObject.getPath());
        }
        importFiles(readers, importers, fileObjects);
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : MostRecentFiles(org.gephi.desktop.mrufiles.api.MostRecentFiles) FileImporter(org.gephi.io.importer.spi.FileImporter) Reader(java.io.Reader) IOException(java.io.IOException) NotifyDescriptor(org.openide.NotifyDescriptor) FileObject(org.openide.filesystems.FileObject) File(java.io.File)

Example 4 with MostRecentFiles

use of org.gephi.desktop.mrufiles.api.MostRecentFiles in project gephi by gephi.

the class WelcomeTopComponent method loadMRU.

private void loadMRU() {
    net.miginfocom.swing.MigLayout migLayout1 = new net.miginfocom.swing.MigLayout();
    migLayout1.setColumnConstraints("[pref]");
    recentPanel.setLayout(migLayout1);
    MostRecentFiles mru = Lookup.getDefault().lookup(MostRecentFiles.class);
    for (String filePath : mru.getMRUFileList()) {
        JXHyperlink fileLink = new JXHyperlink(openAction);
        File file = new File(filePath);
        if (file.exists()) {
            fileLink.setText(file.getName());
            fileLink.putClientProperty(LINK_PATH, file);
            recentPanel.add(fileLink, "wrap");
        }
    }
}
Also used : MostRecentFiles(org.gephi.desktop.mrufiles.api.MostRecentFiles) JXHyperlink(org.jdesktop.swingx.JXHyperlink) File(java.io.File)

Example 5 with MostRecentFiles

use of org.gephi.desktop.mrufiles.api.MostRecentFiles in project gephi by gephi.

the class DesktopImportControllerUI method importFile.

@Override
public void importFile(FileObject fileObject) {
    try {
        final FileImporter importer = controller.getFileImporter(FileUtil.toFile(fileObject));
        if (importer == null) {
            NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(getClass(), "DesktopImportControllerUI.error_no_matching_file_importer"), NotifyDescriptor.WARNING_MESSAGE);
            DialogDisplayer.getDefault().notify(msg);
            return;
        }
        //MRU
        MostRecentFiles mostRecentFiles = Lookup.getDefault().lookup(MostRecentFiles.class);
        mostRecentFiles.addFile(fileObject.getPath());
        ImporterUI ui = controller.getUI(importer);
        if (ui != null) {
            String title = NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.file.ui.dialog.title", ui.getDisplayName());
            JPanel panel = ui.getPanel();
            FileImporter[] fi = (FileImporter[]) Array.newInstance(importer.getClass(), 1);
            fi[0] = importer;
            ui.setup(fi);
            final DialogDescriptor dd = new DialogDescriptor(panel, title);
            if (panel instanceof ValidationPanel) {
                ValidationPanel vp = (ValidationPanel) panel;
                vp.addChangeListener(new ChangeListener() {

                    @Override
                    public void stateChanged(ChangeEvent e) {
                        dd.setValid(!((ValidationPanel) e.getSource()).isProblem());
                    }
                });
            }
            Object result = DialogDisplayer.getDefault().notify(dd);
            if (!result.equals(NotifyDescriptor.OK_OPTION)) {
                ui.unsetup(false);
                return;
            }
            ui.unsetup(true);
        }
        LongTask task = null;
        if (importer instanceof LongTask) {
            task = (LongTask) importer;
        }
        //Execute task
        fileObject = getArchivedFile(fileObject);
        final String containerSource = fileObject.getNameExt();
        final InputStream stream = fileObject.getInputStream();
        String taskName = NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.taskName", containerSource);
        executor.execute(task, new Runnable() {

            @Override
            public void run() {
                try {
                    Container container = controller.importFile(stream, importer);
                    if (container != null) {
                        container.setSource(containerSource);
                        finishImport(container);
                    }
                } catch (Exception ex) {
                    throw new RuntimeException(ex);
                }
            }
        }, taskName, errorHandler);
    } catch (Exception ex) {
        Logger.getLogger("").log(Level.WARNING, "", ex);
    }
}
Also used : ImporterUI(org.gephi.io.importer.spi.ImporterUI) MostRecentFiles(org.gephi.desktop.mrufiles.api.MostRecentFiles) JPanel(javax.swing.JPanel) GZIPInputStream(java.util.zip.GZIPInputStream) BZip2CompressorInputStream(org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileImporter(org.gephi.io.importer.spi.FileImporter) ValidationPanel(org.netbeans.validation.api.ui.ValidationPanel) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) NotifyDescriptor(org.openide.NotifyDescriptor) Container(org.gephi.io.importer.api.Container) ChangeEvent(javax.swing.event.ChangeEvent) LongTask(org.gephi.utils.longtask.spi.LongTask) DialogDescriptor(org.openide.DialogDescriptor) ChangeListener(javax.swing.event.ChangeListener) FileObject(org.openide.filesystems.FileObject)

Aggregations

MostRecentFiles (org.gephi.desktop.mrufiles.api.MostRecentFiles)6 File (java.io.File)3 LongTask (org.gephi.utils.longtask.spi.LongTask)3 FileObject (org.openide.filesystems.FileObject)3 IOException (java.io.IOException)2 FileImporter (org.gephi.io.importer.spi.FileImporter)2 NotifyDescriptor (org.openide.NotifyDescriptor)2 ActionEvent (java.awt.event.ActionEvent)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 AbstractAction (javax.swing.AbstractAction)1 JFrame (javax.swing.JFrame)1 JMenu (javax.swing.JMenu)1 JMenuItem (javax.swing.JMenuItem)1 JPanel (javax.swing.JPanel)1 ChangeEvent (javax.swing.event.ChangeEvent)1 ChangeListener (javax.swing.event.ChangeListener)1