Search in sources :

Example 66 with ActionEvent

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

the class LayoutPanel method initEvents.

private void initEvents() {
    layoutCombobox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (layoutCombobox.getSelectedItem().equals(NO_SELECTION) && model.getSelectedLayout() != null) {
                setSelectedLayout(null);
            } else if (layoutCombobox.getSelectedItem() instanceof LayoutBuilderWrapper) {
                LayoutBuilder builder = ((LayoutBuilderWrapper) layoutCombobox.getSelectedItem()).getLayoutBuilder();
                if (model.getSelectedLayout() == null || model.getSelectedBuilder() != builder) {
                    setSelectedLayout(builder);
                }
            }
        }
    });
    infoLabel.addMouseListener(new MouseAdapter() {

        RichTooltip richTooltip;

        @Override
        public void mouseEntered(MouseEvent e) {
            if (infoLabel.isEnabled() && model != null && model.getSelectedLayout() != null) {
                richTooltip = buildTooltip(model.getSelectedBuilder());
                richTooltip.showTooltip(infoLabel, e.getLocationOnScreen());
            }
        }

        @Override
        public void mouseExited(MouseEvent e) {
            if (richTooltip != null) {
                richTooltip.hideTooltip();
                richTooltip = null;
            }
        }
    });
    presetsButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JPopupMenu menu = new JPopupMenu();
            List<Preset> presets = layoutPresetPersistence.getPresets(model.getSelectedLayout());
            if (presets != null && !presets.isEmpty()) {
                for (final Preset p : presets) {
                    JMenuItem item = new JMenuItem(p.toString());
                    item.addActionListener(new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            layoutPresetPersistence.loadPreset(p, model.getSelectedLayout());
                            refreshProperties();
                            StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.status.loadPreset", model.getSelectedBuilder().getName(), p.toString()));
                        }
                    });
                    menu.add(item);
                }
            } else {
                menu.add("<html><i>" + NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.presetsButton.nopreset") + "</i></html>");
            }
            JMenuItem saveItem = new JMenuItem(NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.presetsButton.savePreset"));
            saveItem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    String lastPresetName = NbPreferences.forModule(LayoutPanel.class).get("LayoutPanel.lastPresetName", "");
                    NotifyDescriptor.InputLine question = new NotifyDescriptor.InputLine(NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.presetsButton.savePreset.input"), NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.presetsButton.savePreset.input.name"));
                    question.setInputText(lastPresetName);
                    if (DialogDisplayer.getDefault().notify(question) == NotifyDescriptor.OK_OPTION) {
                        String input = question.getInputText();
                        if (input != null && !input.isEmpty()) {
                            layoutPresetPersistence.savePreset(input, model.getSelectedLayout());
                            StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.status.savePreset", model.getSelectedBuilder().getName(), input));
                            NbPreferences.forModule(LayoutPanel.class).put("LayoutPanel.lastPresetName", input);
                        }
                    }
                }
            });
            menu.add(new JSeparator());
            menu.add(saveItem);
            menu.show(layoutToolbar, 0, -menu.getPreferredSize().height);
        }
    });
}
Also used : LayoutBuilder(org.gephi.layout.spi.LayoutBuilder) ItemEvent(java.awt.event.ItemEvent) MouseEvent(java.awt.event.MouseEvent) ActionEvent(java.awt.event.ActionEvent) Preset(org.gephi.desktop.layout.LayoutPresetPersistence.Preset) MouseAdapter(java.awt.event.MouseAdapter) JPopupMenu(javax.swing.JPopupMenu) JSeparator(javax.swing.JSeparator) NotifyDescriptor(org.openide.NotifyDescriptor) RichTooltip(org.gephi.ui.components.richtooltip.RichTooltip) ActionListener(java.awt.event.ActionListener) ItemListener(java.awt.event.ItemListener) ArrayList(java.util.ArrayList) List(java.util.List) JMenuItem(javax.swing.JMenuItem)

Example 67 with ActionEvent

use of java.awt.event.ActionEvent 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 68 with ActionEvent

use of java.awt.event.ActionEvent 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 69 with ActionEvent

use of java.awt.event.ActionEvent 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 70 with ActionEvent

use of java.awt.event.ActionEvent 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)

Aggregations

ActionEvent (java.awt.event.ActionEvent)1619 ActionListener (java.awt.event.ActionListener)1289 JButton (javax.swing.JButton)417 JPanel (javax.swing.JPanel)391 JLabel (javax.swing.JLabel)253 JMenuItem (javax.swing.JMenuItem)219 BoxLayout (javax.swing.BoxLayout)172 AbstractAction (javax.swing.AbstractAction)166 FlowLayout (java.awt.FlowLayout)130 Insets (java.awt.Insets)129 GridBagConstraints (java.awt.GridBagConstraints)127 Dimension (java.awt.Dimension)126 GridBagLayout (java.awt.GridBagLayout)120 JMenu (javax.swing.JMenu)118 JScrollPane (javax.swing.JScrollPane)117 JCheckBox (javax.swing.JCheckBox)109 BorderLayout (java.awt.BorderLayout)108 JTextField (javax.swing.JTextField)85 JComboBox (javax.swing.JComboBox)77 ButtonGroup (javax.swing.ButtonGroup)72