Search in sources :

Example 61 with ActionListener

use of java.awt.event.ActionListener in project gephi by gephi.

the class VectorialFileExporterUI method action.

@Override
public void action() {
    final String LAST_PATH = "VectorialFileExporterUI_Last_Path";
    final String LAST_PATH_DEFAULT = "VectorialFileExporterUI_Last_Path_Default";
    final ExportControllerUI exportController = Lookup.getDefault().lookup(ExportControllerUI.class);
    if (exportController == null) {
        return;
    }
    //Get last directory
    String lastPathDefault = NbPreferences.forModule(VectorialFileExporterUI.class).get(LAST_PATH_DEFAULT, null);
    String lastPath = NbPreferences.forModule(VectorialFileExporterUI.class).get(LAST_PATH, lastPathDefault);
    //Options panel
    FlowLayout layout = new FlowLayout(FlowLayout.RIGHT);
    JPanel optionsPanel = new JPanel(layout);
    final JButton optionsButton = new JButton(NbBundle.getMessage(VectorialFileExporterUI.class, "VectorialFileExporterUI_optionsButton_name"));
    optionsPanel.add(optionsButton);
    optionsButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            ExporterUI exporterUI = exportController.getExportController().getUI(selectedExporter);
            if (exporterUI != null) {
                JPanel panel = exporterUI.getPanel();
                exporterUI.setup(selectedExporter);
                DialogDescriptor dd = new DialogDescriptor(panel, NbBundle.getMessage(VectorialFileExporterUI.class, "VectorialFileExporterUI_optionsDialog_title", selectedBuilder.getName()));
                TopDialog topDialog = new TopDialog(dialog, dd.getTitle(), dd.isModal(), dd, dd.getClosingOptions(), dd.getButtonListener());
                topDialog.setVisible(true);
                Object result = (dd.getValue() != null) ? dd.getValue() : NotifyDescriptor.CLOSED_OPTION;
                //                    Object result = DialogDisplayer.getDefault().notify(dd);
                exporterUI.unsetup(result == NotifyDescriptor.OK_OPTION);
            }
        }
    });
    //Graph Settings Panel
    final JPanel southPanel = new JPanel(new BorderLayout());
    southPanel.add(optionsPanel, BorderLayout.NORTH);
    //Optionable file chooser
    final JFileChooser chooser = new JFileChooser(lastPath) {

        @Override
        protected JDialog createDialog(Component parent) throws HeadlessException {
            dialog = super.createDialog(parent);
            Component c = dialog.getContentPane().getComponent(0);
            if (c != null && c instanceof JComponent) {
                Insets insets = ((JComponent) c).getInsets();
                southPanel.setBorder(BorderFactory.createEmptyBorder(insets.top, insets.left, insets.bottom, insets.right));
            }
            dialog.getContentPane().add(southPanel, BorderLayout.SOUTH);
            return dialog;
        }

        @Override
        public void approveSelection() {
            if (canExport(this)) {
                super.approveSelection();
            }
        }
    };
    chooser.setDialogTitle(NbBundle.getMessage(VectorialFileExporterUI.class, "VectorialFileExporterUI_filechooser_title"));
    chooser.addPropertyChangeListener(JFileChooser.FILE_FILTER_CHANGED_PROPERTY, new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            DialogFileFilter fileFilter = (DialogFileFilter) evt.getNewValue();
            //Options panel enabling
            selectedBuilder = getExporter(fileFilter);
            if (selectedBuilder != null) {
                selectedExporter = selectedBuilder.buildExporter();
            }
            if (selectedExporter != null && exportController.getExportController().getUI(selectedExporter) != null) {
                optionsButton.setEnabled(true);
            } else {
                optionsButton.setEnabled(false);
            }
            //Selected file extension change
            if (selectedFile != null && fileFilter != null) {
                String fileName = selectedFile.getName();
                String directoryPath = chooser.getCurrentDirectory().getAbsolutePath();
                if (fileName.lastIndexOf(".") != -1) {
                    fileName = fileName.substring(0, fileName.lastIndexOf("."));
                    fileName = fileName.concat(fileFilter.getExtensions().get(0));
                    selectedFile = new File(directoryPath, fileName);
                    chooser.setSelectedFile(selectedFile);
                }
            }
        }
    });
    chooser.addPropertyChangeListener(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY, new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getNewValue() != null) {
                selectedFile = (File) evt.getNewValue();
            }
        }
    });
    //File filters
    DialogFileFilter defaultFilter = null;
    for (VectorFileExporterBuilder vectorFileExporter : Lookup.getDefault().lookupAll(VectorFileExporterBuilder.class)) {
        for (FileType fileType : vectorFileExporter.getFileTypes()) {
            DialogFileFilter dialogFileFilter = new DialogFileFilter(fileType.getName());
            dialogFileFilter.addExtensions(fileType.getExtensions());
            if (defaultFilter == null) {
                defaultFilter = dialogFileFilter;
            }
            chooser.addChoosableFileFilter(dialogFileFilter);
        }
    }
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.setFileFilter(defaultFilter);
    selectedFile = new File(chooser.getCurrentDirectory(), "Untitled" + defaultFilter.getExtensions().get(0));
    chooser.setSelectedFile(selectedFile);
    //Show
    int returnFile = chooser.showSaveDialog(null);
    if (returnFile == JFileChooser.APPROVE_OPTION) {
        File file = chooser.getSelectedFile();
        file = FileUtil.normalizeFile(file);
        FileObject fileObject = FileUtil.toFileObject(file);
        //Save last path
        NbPreferences.forModule(VectorialFileExporterUI.class).put(LAST_PATH, file.getAbsolutePath());
        //Do
        exportController.exportFile(fileObject, selectedExporter);
    }
    dialog = null;
}
Also used : JPanel(javax.swing.JPanel) VectorFileExporterBuilder(org.gephi.io.exporter.spi.VectorFileExporterBuilder) FlowLayout(java.awt.FlowLayout) Insets(java.awt.Insets) ExporterUI(org.gephi.io.exporter.spi.ExporterUI) PropertyChangeListener(java.beans.PropertyChangeListener) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) BorderLayout(java.awt.BorderLayout) FileObject(org.openide.filesystems.FileObject) JComponent(javax.swing.JComponent) Component(java.awt.Component) DialogFileFilter(org.gephi.ui.utils.DialogFileFilter) PropertyChangeEvent(java.beans.PropertyChangeEvent) JComponent(javax.swing.JComponent) ExportControllerUI(org.gephi.desktop.io.export.ExportControllerUI) ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) FileType(org.gephi.io.exporter.api.FileType) DialogDescriptor(org.openide.DialogDescriptor) FileObject(org.openide.filesystems.FileObject) File(java.io.File)

Example 62 with ActionListener

use of java.awt.event.ActionListener 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 63 with ActionListener

use of java.awt.event.ActionListener in project gephi by gephi.

the class DataTableTopComponent method preparePluginGeneralActionsButton.

/**
     * Prepare a button for the popup panel for plugin general actions.
     *
     * @param m PluginGeneralActionsManipulator for the button
     * @return JCommandButton for the manipulator
     */
private JCommandButton preparePluginGeneralActionsButton(final PluginGeneralActionsManipulator m) {
    //Convert icon to Image if it is not null
    JCommandButton button = new JCommandButton(m.getName(), m.getIcon() != null ? ImageWrapperResizableIcon.getIcon(ImageUtilities.icon2Image(m.getIcon()), new Dimension(16, 16)) : null);
    button.setDisplayState(CommandButtonDisplayState.BIG);
    button.setCommandButtonKind(JCommandButton.CommandButtonKind.ACTION_ONLY);
    if (m.getDescription() != null && !m.getDescription().isEmpty()) {
        button.setPopupRichTooltip(new RichTooltip(NbBundle.getMessage(DataTableTopComponent.class, "DataTableTopComponent.RichToolTip.title.text"), m.getDescription()));
    }
    if (m.canExecute()) {
        button.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                DataLaboratoryHelper.getDefault().executeManipulator(m);
            }
        });
    } else {
        button.setEnabled(false);
    }
    return button;
}
Also used : RichTooltip(org.pushingpixels.flamingo.api.common.RichTooltip) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JCommandButton(org.pushingpixels.flamingo.api.common.JCommandButton) Dimension(java.awt.Dimension)

Example 64 with ActionListener

use of java.awt.event.ActionListener in project gephi by gephi.

the class DataTableTopComponent method prepareAddColumnButton.

/**
     * Create the special Add new column button.
     */
private void prepareAddColumnButton() {
    JCommandButtonStrip strip = new JCommandButtonStrip(JCommandButtonStrip.StripOrientation.HORIZONTAL);
    strip.setDisplayState(CommandButtonDisplayState.BIG);
    JCommandButton button = new JCommandButton(NbBundle.getMessage(DataTableTopComponent.class, "DataTableTopComponent.addColumnButton.text"), ImageWrapperResizableIcon.getIcon(ImageUtilities.loadImage("org/gephi/desktop/datalab/resources/table-insert-column.png", true), new Dimension(16, 16)));
    button.setCommandButtonKind(JCommandButton.CommandButtonKind.ACTION_ONLY);
    button.setDisplayState(CommandButtonDisplayState.BIG);
    if (isShowingNodesTable()) {
        button.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                showAddColumnUI(AddColumnUI.Mode.NODES_TABLE);
            }
        });
    } else {
        button.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                showAddColumnUI(AddColumnUI.Mode.EDGES_TABLE);
            }
        });
    }
    strip.add(button);
    columnManipulatorsPanel.add(strip);
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JCommandButton(org.pushingpixels.flamingo.api.common.JCommandButton) Dimension(java.awt.Dimension) JCommandButtonStrip(org.pushingpixels.flamingo.api.common.JCommandButtonStrip)

Example 65 with ActionListener

use of java.awt.event.ActionListener in project gephi by gephi.

the class DataTableTopComponent method initEvents.

private void initEvents() {
    //Workspace Listener
    pc.addWorkspaceListener(new WorkspaceListener() {

        @Override
        public void initialize(Workspace workspace) {
            //Prepare DataTablesEvent listener
            Lookup.getDefault().lookup(DataTablesController.class).setDataTablesEventListener(DataTableTopComponent.this);
            if (workspace.getLookup().lookup(DataTablesModel.class) == null) {
                workspace.add(new DataTablesModel(workspace));
            }
        }

        @Override
        public void select(Workspace workspace) {
            activateWorkspace(workspace);
            setAutoRefreshEnabled(true);
        }

        @Override
        public void unselect(Workspace workspace) {
            deactivateAll();
            setAutoRefreshEnabled(false);
        }

        @Override
        public void close(Workspace workspace) {
        }

        @Override
        public void disable() {
            clearAll();
            //No more workspaces active, disable the DataTablesEvent listener
            Lookup.getDefault().lookup(DataTablesController.class).setDataTablesEventListener(null);
            setAutoRefreshEnabled(false);
        }
    });
    if (pc.getCurrentWorkspace() != null) {
        activateWorkspace(pc.getCurrentWorkspace());
        setAutoRefreshEnabled(true);
    }
    observersTimer = new java.util.Timer("DataLaboratoryGraphObservers");
    observersTimer.schedule(new TimerTask() {

        @Override
        public void run() {
            if (!autoRefreshEnabled) {
                return;
            }
            if (dataTablesObservers != null) {
                if (dataTablesObservers.hasChanges()) {
                    //Execute refresh
                    graphChanged();
                }
            }
        }
    }, 0, //Check graph and tables for changes every 100 ms
    AUTO_REFRESH_RATE_MILLISECONDS);
    //Filter
    if (dynamicFiltering) {
        filterTextField.getDocument().addDocumentListener(new DocumentListener() {

            @Override
            public void insertUpdate(DocumentEvent e) {
                refreshAppliedFilter();
            }

            @Override
            public void removeUpdate(DocumentEvent e) {
                refreshAppliedFilter();
            }

            @Override
            public void changedUpdate(DocumentEvent e) {
            }
        });
    } else {
        filterTextField.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                refreshAppliedFilter();
            }
        });
    }
    columnComboBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            refreshAppliedFilter();
        }
    });
    initKeyEventContextMenuActionMappings();
}
Also used : DocumentListener(javax.swing.event.DocumentListener) WorkspaceListener(org.gephi.project.api.WorkspaceListener) TimerTask(java.util.TimerTask) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) DocumentEvent(javax.swing.event.DocumentEvent) Workspace(org.gephi.project.api.Workspace)

Aggregations

ActionListener (java.awt.event.ActionListener)1347 ActionEvent (java.awt.event.ActionEvent)1303 JButton (javax.swing.JButton)363 JPanel (javax.swing.JPanel)345 JLabel (javax.swing.JLabel)234 JMenuItem (javax.swing.JMenuItem)191 BoxLayout (javax.swing.BoxLayout)150 GridBagConstraints (java.awt.GridBagConstraints)121 Insets (java.awt.Insets)121 GridBagLayout (java.awt.GridBagLayout)114 Dimension (java.awt.Dimension)113 FlowLayout (java.awt.FlowLayout)110 JCheckBox (javax.swing.JCheckBox)103 JScrollPane (javax.swing.JScrollPane)103 JMenu (javax.swing.JMenu)96 BorderLayout (java.awt.BorderLayout)88 JTextField (javax.swing.JTextField)79 JComboBox (javax.swing.JComboBox)73 ButtonGroup (javax.swing.ButtonGroup)64 ArrayList (java.util.ArrayList)60