Search in sources :

Example 6 with ProjectControllerUI

use of org.gephi.desktop.project.api.ProjectControllerUI in project gephi by gephi.

the class SaveAsProject method actionPerformed.

@Override
public void actionPerformed(ActionEvent ev) {
    ProjectControllerUI pcui = Lookup.getDefault().lookup(ProjectControllerUI.class);
    pcui.saveAsProject();
}
Also used : ProjectControllerUI(org.gephi.desktop.project.api.ProjectControllerUI)

Example 7 with ProjectControllerUI

use of org.gephi.desktop.project.api.ProjectControllerUI 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 8 with ProjectControllerUI

use of org.gephi.desktop.project.api.ProjectControllerUI in project gephi by gephi.

the class CommandLineProcessor method process.

@Override
public void process(Env env, Map values) throws CommandException {
    List<String> filenameList = new ArrayList<>();
    Object obj = values.get(openOption);
    if (obj != null) {
        filenameList.addAll(Arrays.asList((String[]) obj));
    }
    obj = values.get(openOption2);
    if (obj != null) {
        filenameList.addAll(Arrays.asList((String[]) obj));
    }
    try {
        for (int i = 0; i < filenameList.size(); i++) {
            File file = new File(filenameList.get(i));
            if (!file.isAbsolute()) {
                file = new File(env.getCurrentDirectory(), filenameList.get(i));
            }
            FileObject fileObject = FileUtil.toFileObject(file);
            if (!file.exists()) {
                NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(CommandLineProcessor.class, "CommandLineProcessor.fileNotFound", file.getName()), NotifyDescriptor.WARNING_MESSAGE);
                DialogDisplayer.getDefault().notify(msg);
                return;
            }
            if (fileObject.hasExt(GEPHI_EXTENSION)) {
                ProjectControllerUI pc = Lookup.getDefault().lookup(ProjectControllerUI.class);
                try {
                    pc.openProject(file);
                } catch (Exception ew) {
                    ew.printStackTrace();
                    NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(CommandLineProcessor.class, "CommandLineProcessor.openGephiError"), NotifyDescriptor.WARNING_MESSAGE);
                    DialogDisplayer.getDefault().notify(msg);
                }
                return;
            } else {
                ImportControllerUI importController = Lookup.getDefault().lookup(ImportControllerUI.class);
                if (importController.getImportController().isFileSupported(FileUtil.toFile(fileObject))) {
                    importController.importFile(fileObject);
                } else {
                    NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(CommandLineProcessor.class, "CommandLineProcessor.fileNotSupported"), NotifyDescriptor.WARNING_MESSAGE);
                    DialogDisplayer.getDefault().notify(msg);
                }
            }
        }
    } catch (OutOfMemoryError ex) {
        System.gc();
        NotifyDescriptor nd = new NotifyDescriptor.Message(MEMORY_ERROR, NotifyDescriptor.ERROR_MESSAGE);
        DialogDisplayer.getDefault().notify(nd);
    } catch (Exception ex) {
        ex.printStackTrace();
        NotifyDescriptor nd = new NotifyDescriptor.Message("CommandLineParsing " + ex.getMessage(), NotifyDescriptor.ERROR_MESSAGE);
        DialogDisplayer.getDefault().notify(nd);
    }
}
Also used : ArrayList(java.util.ArrayList) CommandException(org.netbeans.api.sendopts.CommandException) NotifyDescriptor(org.openide.NotifyDescriptor) ImportControllerUI(org.gephi.desktop.importer.api.ImportControllerUI) FileObject(org.openide.filesystems.FileObject) FileObject(org.openide.filesystems.FileObject) File(java.io.File) ProjectControllerUI(org.gephi.desktop.project.api.ProjectControllerUI)

Example 9 with ProjectControllerUI

use of org.gephi.desktop.project.api.ProjectControllerUI in project gephi by gephi.

the class DragNDropFrameAdapter method register.

public static void register() {
    JFrame frame = (JFrame) WindowManager.getDefault().getMainWindow();
    frame.setTransferHandler(new TransferHandler() {

        @Override
        public boolean canImport(TransferHandler.TransferSupport support) {
            if (!support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
                return false;
            }
            //Impossible to get data here and look if compatible format
            return true;
        }

        @Override
        public boolean importData(TransferHandler.TransferSupport support) {
            if (!canImport(support)) {
                return false;
            }
            try {
                List data = (List) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
                File file = (File) data.get(0);
                FileObject fileObject = FileUtil.toFileObject(file);
                if (!file.exists()) {
                    return false;
                }
                if (fileObject.hasExt(GEPHI_EXTENSION)) {
                    ProjectControllerUI pc = Lookup.getDefault().lookup(ProjectControllerUI.class);
                    try {
                        pc.openProject(file);
                    } catch (Exception ew) {
                        ew.printStackTrace();
                        NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(DragNDropFrameAdapter.class, "DragNDropFrameAdapter.openGephiError"), NotifyDescriptor.WARNING_MESSAGE);
                        DialogDisplayer.getDefault().notify(msg);
                    }
                } else {
                    ImportControllerUI importController = Lookup.getDefault().lookup(ImportControllerUI.class);
                    if (importController.getImportController().isFileSupported(FileUtil.toFile(fileObject))) {
                        importController.importFile(fileObject);
                    } else {
                        return false;
                    }
                }
                return true;
            } catch (UnsupportedFlavorException ex) {
                Exceptions.printStackTrace(ex);
            } catch (IOException ex) {
                Exceptions.printStackTrace(ex);
            }
            return false;
        }
    });
}
Also used : IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException) NotifyDescriptor(org.openide.NotifyDescriptor) JFrame(javax.swing.JFrame) ImportControllerUI(org.gephi.desktop.importer.api.ImportControllerUI) TransferHandler(javax.swing.TransferHandler) List(java.util.List) FileObject(org.openide.filesystems.FileObject) File(java.io.File) ProjectControllerUI(org.gephi.desktop.project.api.ProjectControllerUI)

Aggregations

ProjectControllerUI (org.gephi.desktop.project.api.ProjectControllerUI)9 FileObject (org.openide.filesystems.FileObject)5 File (java.io.File)4 ImportControllerUI (org.gephi.desktop.importer.api.ImportControllerUI)4 ProjectController (org.gephi.project.api.ProjectController)3 NotifyDescriptor (org.openide.NotifyDescriptor)3 ActionEvent (java.awt.event.ActionEvent)2 ArrayList (java.util.ArrayList)2 AbstractAction (javax.swing.AbstractAction)2 Workspace (org.gephi.project.api.Workspace)2 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 ActionListener (java.awt.event.ActionListener)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 List (java.util.List)1 Random (java.util.Random)1 JFrame (javax.swing.JFrame)1 JMenu (javax.swing.JMenu)1 JMenuItem (javax.swing.JMenuItem)1 JPanel (javax.swing.JPanel)1