Search in sources :

Example 1 with JCommandMenuButton

use of org.pushingpixels.flamingo.api.common.JCommandMenuButton in project gephi by gephi.

the class DataTableTopComponent method prepareJCommandButton.

/**
     * Creates a JCommandButton for the specified columns of a table and
     * AttributeColumnsManipulator
     *
     * @param graphModel graph model
     * @param table table
     * @param columns Columns
     * @param acm AttributeColumnsManipulator
     * @return Prepared JCommandButton
     */
private JCommandButton prepareJCommandButton(final GraphModel graphModel, final Table table, final Column[] columns, final AttributeColumnsManipulator acm) {
    JCommandButton manipulatorButton;
    if (acm.getIcon() != null) {
        manipulatorButton = new JCommandButton(acm.getName(), ImageWrapperResizableIcon.getIcon(acm.getIcon(), new Dimension(16, 16)));
    } else {
        manipulatorButton = new JCommandButton(acm.getName());
    }
    manipulatorButton.setCommandButtonKind(JCommandButton.CommandButtonKind.POPUP_ONLY);
    manipulatorButton.setDisplayState(CommandButtonDisplayState.MEDIUM);
    if (acm.getDescription() != null && !acm.getDescription().isEmpty()) {
        manipulatorButton.setPopupRichTooltip(new RichTooltip(NbBundle.getMessage(DataTableTopComponent.class, "DataTableTopComponent.RichToolTip.title.text"), acm.getDescription()));
    }
    final ArrayList<Column> availableColumns = new ArrayList<>();
    for (final Column column : columns) {
        if (acm.canManipulateColumn(table, column)) {
            availableColumns.add(column);
        }
    }
    if (!availableColumns.isEmpty()) {
        manipulatorButton.setPopupCallback(new PopupPanelCallback() {

            @Override
            public JPopupPanel getPopupPanel(JCommandButton jcb) {
                JCommandPopupMenu popup = new JCommandPopupMenu();
                JCommandMenuButton button;
                for (final Column column : availableColumns) {
                    button = new JCommandMenuButton(column.getTitle(), ImageWrapperResizableIcon.getIcon(ImageUtilities.loadImage("org/gephi/desktop/datalab/resources/column.png"), new Dimension(16, 16)));
                    button.addActionListener(new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            DataLaboratoryHelper.getDefault().executeAttributeColumnsManipulator(acm, graphModel, table, column);
                        }
                    });
                    popup.addMenuButton(button);
                }
                return popup;
            }
        });
    } else {
        manipulatorButton.setEnabled(false);
    }
    return manipulatorButton;
}
Also used : ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) PopupPanelCallback(org.pushingpixels.flamingo.api.common.popup.PopupPanelCallback) JPopupPanel(org.pushingpixels.flamingo.api.common.popup.JPopupPanel) JCommandButton(org.pushingpixels.flamingo.api.common.JCommandButton) Dimension(java.awt.Dimension) RichTooltip(org.pushingpixels.flamingo.api.common.RichTooltip) JCommandMenuButton(org.pushingpixels.flamingo.api.common.JCommandMenuButton) ActionListener(java.awt.event.ActionListener) Column(org.gephi.graph.api.Column) JCommandPopupMenu(org.pushingpixels.flamingo.api.common.popup.JCommandPopupMenu)

Aggregations

Dimension (java.awt.Dimension)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ArrayList (java.util.ArrayList)1 Column (org.gephi.graph.api.Column)1 JCommandButton (org.pushingpixels.flamingo.api.common.JCommandButton)1 JCommandMenuButton (org.pushingpixels.flamingo.api.common.JCommandMenuButton)1 RichTooltip (org.pushingpixels.flamingo.api.common.RichTooltip)1 JCommandPopupMenu (org.pushingpixels.flamingo.api.common.popup.JCommandPopupMenu)1 JPopupPanel (org.pushingpixels.flamingo.api.common.popup.JPopupPanel)1 PopupPanelCallback (org.pushingpixels.flamingo.api.common.popup.PopupPanelCallback)1