Search in sources :

Example 1 with ImportControllerUI

use of org.gephi.desktop.importer.api.ImportControllerUI in project gephi by gephi.

the class ImportDB method getMenuPresenter.

@Override
public JMenuItem getMenuPresenter() {
    JMenu menu = new JMenu(NbBundle.getMessage(ImportDB.class, "CTL_ImportDB"));
    final ImportControllerUI importController = Lookup.getDefault().lookup(ImportControllerUI.class);
    if (importController != null) {
        for (final DatabaseImporterBuilder dbb : Lookup.getDefault().lookupAll(DatabaseImporterBuilder.class)) {
            ImporterUI ui = importController.getImportController().getUI(dbb.buildImporter());
            String menuName = dbb.getName();
            if (ui != null) {
                menuName = ui.getDisplayName();
            }
            JMenuItem menuItem = new JMenuItem(new AbstractAction(menuName) {

                @Override
                public void actionPerformed(ActionEvent e) {
                    importController.importDatabase(dbb.buildImporter());
                }
            });
            menu.add(menuItem);
        }
    }
    return menu;
}
Also used : ImporterUI(org.gephi.io.importer.spi.ImporterUI) ImportControllerUI(org.gephi.desktop.importer.api.ImportControllerUI) ActionEvent(java.awt.event.ActionEvent) JMenuItem(javax.swing.JMenuItem) AbstractAction(javax.swing.AbstractAction) JMenu(javax.swing.JMenu) DatabaseImporterBuilder(org.gephi.io.importer.spi.DatabaseImporterBuilder)

Example 2 with ImportControllerUI

use of org.gephi.desktop.importer.api.ImportControllerUI in project gephi by gephi.

the class WelcomeTopComponent method initAction.

private void initAction() {
    openAction = new AbstractAction("", ImageUtilities.loadImageIcon("org/gephi/desktop/welcome/resources/gephifile20.png", false)) {

        @Override
        public void actionPerformed(ActionEvent e) {
            JXHyperlink link = (JXHyperlink) e.getSource();
            File file = (File) link.getClientProperty(LINK_PATH);
            FileObject fileObject = FileUtil.toFileObject(file);
            if (fileObject.hasExt(GEPHI_EXTENSION)) {
                ProjectControllerUI pc = Lookup.getDefault().lookup(ProjectControllerUI.class);
                try {
                    pc.openProject(file);
                } catch (Exception ex) {
                    ex.printStackTrace();
                    NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(WelcomeTopComponent.class, "WelcomeTopComponent.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);
                }
            }
            closeDialog();
        }
    };
    newProjectLink.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            ProjectControllerUI pc = Lookup.getDefault().lookup(ProjectControllerUI.class);
            pc.newProject();
            closeDialog();
        }
    });
    openFileLink.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            ProjectControllerUI pc = Lookup.getDefault().lookup(ProjectControllerUI.class);
            pc.openFile();
            closeDialog();
        }
    });
}
Also used : ActionEvent(java.awt.event.ActionEvent) JXHyperlink(org.jdesktop.swingx.JXHyperlink) NotifyDescriptor(org.openide.NotifyDescriptor) ActionListener(java.awt.event.ActionListener) ImportControllerUI(org.gephi.desktop.importer.api.ImportControllerUI) FileObject(org.openide.filesystems.FileObject) AbstractAction(javax.swing.AbstractAction) File(java.io.File) ProjectControllerUI(org.gephi.desktop.project.api.ProjectControllerUI)

Example 3 with ImportControllerUI

use of org.gephi.desktop.importer.api.ImportControllerUI in project gephi by gephi.

the class WelcomeTopComponent method loadSamples.

private void loadSamples() {
    net.miginfocom.swing.MigLayout migLayout1 = new net.miginfocom.swing.MigLayout();
    migLayout1.setColumnConstraints("[pref]");
    samplesPanel.setLayout(migLayout1);
    String[] samplePath = new String[3];
    samplePath[0] = "/org/gephi/desktop/welcome/samples/Les Miserables.gexf";
    samplePath[1] = "/org/gephi/desktop/welcome/samples/Java.gexf";
    samplePath[2] = "/org/gephi/desktop/welcome/samples/Power Grid.gml";
    String[] sampleTooltip = new String[3];
    sampleTooltip[0] = "Coappearance Network of Characters in 'Les Miserables' (D. E. Knuth)";
    sampleTooltip[1] = "Java Programming Language Dependency graph (V. Batagelj)";
    sampleTooltip[2] = "Topology of the Western States Power Grid of the US (D. Watts & S. Strogatz)";
    try {
        for (int i = 0; i < samplePath.length; i++) {
            final String s = samplePath[i];
            String tooltip = sampleTooltip[i];
            String fileName = s.substring(s.lastIndexOf('/') + 1, s.length());
            final String importer = fileName.substring(fileName.lastIndexOf('.'), fileName.length());
            JXHyperlink fileLink = new JXHyperlink(new AbstractAction() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    final InputStream stream = WelcomeTopComponent.class.getResourceAsStream(s);
                    ImportControllerUI importController = Lookup.getDefault().lookup(ImportControllerUI.class);
                    importController.importStream(stream, importer);
                    closeDialog();
                }
            });
            fileLink.setText(fileName);
            fileLink.setToolTipText(tooltip);
            fileLink.putClientProperty(LINK_PATH, importer);
            samplesPanel.add(fileLink, "wrap");
        }
    } catch (Exception ex) {
        Exceptions.printStackTrace(ex);
    }
}
Also used : ActionEvent(java.awt.event.ActionEvent) InputStream(java.io.InputStream) JXHyperlink(org.jdesktop.swingx.JXHyperlink) ImportControllerUI(org.gephi.desktop.importer.api.ImportControllerUI) AbstractAction(javax.swing.AbstractAction)

Example 4 with ImportControllerUI

use of org.gephi.desktop.importer.api.ImportControllerUI in project gephi by gephi.

the class ProjectControllerUIImpl method openFile.

@Override
public void openFile() {
    final String LAST_PATH = "OpenFile_Last_Path";
    final String LAST_PATH_DEFAULT = "OpenFile_Last_Path_Default";
    //Get last directory
    String lastPathDefault = NbPreferences.forModule(ProjectControllerUIImpl.class).get(LAST_PATH_DEFAULT, null);
    String lastPath = NbPreferences.forModule(ProjectControllerUIImpl.class).get(LAST_PATH, lastPathDefault);
    //Init dialog
    final JFileChooser chooser = new JFileChooser(lastPath);
    chooser.setMultiSelectionEnabled(true);
    DialogFileFilter gephiFilter = new DialogFileFilter(NbBundle.getMessage(ProjectControllerUIImpl.class, "OpenProject_filechooser_filter"));
    gephiFilter.addExtension(".gephi");
    DialogFileFilter graphFilter = new DialogFileFilter(NbBundle.getMessage(getClass(), "OpenFile_filechooser_graphfilter"));
    graphFilter.addExtension(".gephi");
    ImportControllerUI importController = Lookup.getDefault().lookup(ImportControllerUI.class);
    for (FileType fileType : importController.getImportController().getFileTypes()) {
        DialogFileFilter dialogFileFilter = new DialogFileFilter(fileType.getName());
        dialogFileFilter.addExtensions(fileType.getExtensions());
        chooser.addChoosableFileFilter(dialogFileFilter);
        graphFilter.addExtensions(fileType.getExtensions());
    }
    DialogFileFilter zipFileFilter = new DialogFileFilter(NbBundle.getMessage(getClass(), "OpenFile_filechooser_zipfilter"));
    zipFileFilter.addExtensions(new String[] { ".zip", ".gz", ".bz2" });
    chooser.addChoosableFileFilter(zipFileFilter);
    chooser.addChoosableFileFilter(gephiFilter);
    chooser.addChoosableFileFilter(graphFilter);
    //Open dialog
    int returnFile = chooser.showOpenDialog(null);
    if (returnFile == JFileChooser.APPROVE_OPTION) {
        File[] files = chooser.getSelectedFiles();
        FileObject[] fileObjects = new FileObject[files.length];
        int i = 0;
        File gephiFile = null;
        for (File file : files) {
            file = FileUtil.normalizeFile(file);
            FileObject fileObject = FileUtil.toFileObject(file);
            fileObjects[i++] = fileObject;
            if (fileObject.getExt().equalsIgnoreCase("gephi")) {
                if (gephiFile != null) {
                    NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(ProjectControllerUIImpl.class, "ProjectControllerUI.error.multipleGephi"), NotifyDescriptor.ERROR_MESSAGE);
                    DialogDisplayer.getDefault().notify(msg);
                    return;
                } else {
                    gephiFile = file;
                }
            }
            //Save last path
            NbPreferences.forModule(ProjectControllerUIImpl.class).put(LAST_PATH, file.getAbsolutePath());
        }
        if (gephiFile != null) {
            //Project
            if (controller.getCurrentProject() != null) {
                if (!closeCurrentProject()) {
                    return;
                }
            }
            try {
                loadProject(gephiFile);
            } catch (Exception ew) {
                ew.printStackTrace();
                NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(ProjectControllerUIImpl.class, "OpenProject.defaulterror"), NotifyDescriptor.WARNING_MESSAGE);
                DialogDisplayer.getDefault().notify(msg);
            }
        } else {
            //Import
            importController.importFiles(fileObjects);
        }
    }
}
Also used : NotifyDescriptor(org.openide.NotifyDescriptor) JFileChooser(javax.swing.JFileChooser) FileType(org.gephi.io.importer.api.FileType) ImportControllerUI(org.gephi.desktop.importer.api.ImportControllerUI) FileObject(org.openide.filesystems.FileObject) DialogFileFilter(org.gephi.ui.utils.DialogFileFilter) File(java.io.File)

Example 5 with ImportControllerUI

use of org.gephi.desktop.importer.api.ImportControllerUI 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)

Aggregations

ImportControllerUI (org.gephi.desktop.importer.api.ImportControllerUI)8 File (java.io.File)5 NotifyDescriptor (org.openide.NotifyDescriptor)5 FileObject (org.openide.filesystems.FileObject)5 ActionEvent (java.awt.event.ActionEvent)4 AbstractAction (javax.swing.AbstractAction)4 ProjectControllerUI (org.gephi.desktop.project.api.ProjectControllerUI)4 JMenu (javax.swing.JMenu)2 JMenuItem (javax.swing.JMenuItem)2 JXHyperlink (org.jdesktop.swingx.JXHyperlink)2 Dialog (java.awt.Dialog)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 ActionListener (java.awt.event.ActionListener)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 MessageFormat (java.text.MessageFormat)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JFileChooser (javax.swing.JFileChooser)1 JFrame (javax.swing.JFrame)1