Search in sources :

Example 21 with ChangeEvent

use of javax.swing.event.ChangeEvent in project gephi by gephi.

the class StatisticsFrontEnd method run.

private void run() {
    GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
    GraphModel graphModel = graphController.getGraphModel();
    //Create Statistics
    StatisticsController controller = Lookup.getDefault().lookup(StatisticsController.class);
    StatisticsControllerUI controllerUI = Lookup.getDefault().lookup(StatisticsControllerUI.class);
    StatisticsBuilder builder = controller.getBuilder(statisticsUI.getStatisticsClass());
    currentStatistics = builder.getStatistics();
    if (currentStatistics != null) {
        if (currentStatistics instanceof DynamicStatistics && !graphModel.isDynamic()) {
            DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message(NbBundle.getMessage(StatisticsFrontEnd.class, "StatisticsFrontEnd.notDynamicGraph"), NotifyDescriptor.WARNING_MESSAGE));
            return;
        }
        LongTaskListener listener = new LongTaskListener() {

            @Override
            public void taskFinished(LongTask task) {
                showReport();
            }
        };
        JPanel settingsPanel = statisticsUI.getSettingsPanel();
        if (currentStatistics instanceof DynamicStatistics) {
            DynamicSettingsPanel dynamicPanel = new DynamicSettingsPanel();
            statisticsUI.setup(currentStatistics);
            dynamicPanel.setup((DynamicStatistics) currentStatistics);
            JPanel dynamicSettingsPanel = DynamicSettingsPanel.createCounpoundPanel(dynamicPanel, settingsPanel);
            final DialogDescriptor dd = new DialogDescriptor(dynamicSettingsPanel, NbBundle.getMessage(StatisticsTopComponent.class, "StatisticsFrontEnd.settingsPanel.title", builder.getName()));
            if (dynamicSettingsPanel instanceof ValidationPanel) {
                ValidationPanel vp = (ValidationPanel) dynamicSettingsPanel;
                vp.addChangeListener(new ChangeListener() {

                    @Override
                    public void stateChanged(ChangeEvent e) {
                        dd.setValid(!((ValidationPanel) e.getSource()).isProblem());
                    }
                });
            }
            if (DialogDisplayer.getDefault().notify(dd).equals(NotifyDescriptor.OK_OPTION)) {
                dynamicPanel.unsetup((DynamicStatistics) currentStatistics);
                statisticsUI.unsetup();
                controllerUI.execute(currentStatistics, listener);
            }
        } else if (settingsPanel != null) {
            statisticsUI.setup(currentStatistics);
            final DialogDescriptor dd = new DialogDescriptor(settingsPanel, NbBundle.getMessage(StatisticsTopComponent.class, "StatisticsFrontEnd.settingsPanel.title", builder.getName()));
            if (settingsPanel instanceof ValidationPanel) {
                ValidationPanel vp = (ValidationPanel) settingsPanel;
                vp.addChangeListener(new ChangeListener() {

                    @Override
                    public void stateChanged(ChangeEvent e) {
                        dd.setValid(!((ValidationPanel) e.getSource()).isProblem());
                    }
                });
            }
            if (DialogDisplayer.getDefault().notify(dd).equals(NotifyDescriptor.OK_OPTION)) {
                statisticsUI.unsetup();
                controllerUI.execute(currentStatistics, listener);
            }
        } else {
            statisticsUI.setup(currentStatistics);
            controllerUI.execute(currentStatistics, listener);
        }
    }
}
Also used : JPanel(javax.swing.JPanel) LongTaskListener(org.gephi.utils.longtask.api.LongTaskListener) DynamicStatistics(org.gephi.statistics.spi.DynamicStatistics) StatisticsBuilder(org.gephi.statistics.spi.StatisticsBuilder) ValidationPanel(org.netbeans.validation.api.ui.ValidationPanel) NotifyDescriptor(org.openide.NotifyDescriptor) StatisticsController(org.gephi.statistics.api.StatisticsController) LongTask(org.gephi.utils.longtask.spi.LongTask) ChangeEvent(javax.swing.event.ChangeEvent) GraphModel(org.gephi.graph.api.GraphModel) DialogDescriptor(org.openide.DialogDescriptor) ChangeListener(javax.swing.event.ChangeListener) GraphController(org.gephi.graph.api.GraphController) StatisticsControllerUI(org.gephi.desktop.statistics.api.StatisticsControllerUI)

Example 22 with ChangeEvent

use of javax.swing.event.ChangeEvent in project gephi by gephi.

the class DesktopToolController method getToolbar.

@Override
public JComponent getToolbar() {
    //Get tools ui
    HashMap<ToolUI, Tool> toolMap = new HashMap<>();
    List<ToolUI> toolsUI = new ArrayList<>();
    for (Tool tool : tools) {
        ToolUI ui = tool.getUI();
        if (ui != null) {
            toolsUI.add(ui);
            toolMap.put(ui, tool);
        }
    }
    //Sort by priority
    Collections.sort(toolsUI, new Comparator() {

        @Override
        public int compare(Object o1, Object o2) {
            Integer p1 = ((ToolUI) o1).getPosition();
            Integer p2 = ((ToolUI) o2).getPosition();
            return p1.compareTo(p2);
        }
    });
    //Create toolbar
    final Toolbar toolbar = new Toolbar();
    for (final ToolUI toolUI : toolsUI) {
        final Tool tool = toolMap.get(toolUI);
        JToggleButton btn;
        if (toolUI.getIcon() != null) {
            btn = new JToggleButton(toolUI.getIcon());
        } else {
            btn = new JToggleButton(new ImageIcon(getClass().getResource("/org/gephi/desktop/tools/tool.png")));
        }
        btn.setToolTipText(toolUI.getName() + " - " + toolUI.getDescription());
        btn.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                //Let the user unselect a tool (by clicking on it again) without having to select other tool:
                if (tool == currentTool) {
                    toolbar.clearSelection();
                    unselect();
                } else {
                    try {
                        select(tool);
                        propertiesBar.select(toolUI.getPropertiesBar(tool));
                    } catch (UnselectToolException unselectToolException) {
                        toolbar.clearSelection();
                        unselect();
                    }
                }
            }
        });
        toolbar.add(btn);
    }
    //SelectionManager events
    VizController.getInstance().getSelectionManager().addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            SelectionManager selectionManager = VizController.getInstance().getSelectionManager();
            if (selectionManager.isRectangleSelection() && currentTool != null) {
                toolbar.clearSelection();
                unselect();
            } else if (selectionManager.isSelectionEnabled() && currentTool != null && currentTool.getSelectionType() == ToolSelectionType.NONE) {
                toolbar.clearSelection();
                unselect();
            } else if (selectionManager.isDraggingEnabled() && currentTool != null) {
                toolbar.clearSelection();
                unselect();
            }
        }
    });
    return toolbar;
}
Also used : ImageIcon(javax.swing.ImageIcon) SelectionManager(org.gephi.visualization.api.selection.SelectionManager) HashMap(java.util.HashMap) UnselectToolException(org.gephi.tools.spi.UnselectToolException) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) ToolUI(org.gephi.tools.spi.ToolUI) Comparator(java.util.Comparator) JToggleButton(javax.swing.JToggleButton) ActionListener(java.awt.event.ActionListener) ChangeEvent(javax.swing.event.ChangeEvent) ChangeListener(javax.swing.event.ChangeListener) Tool(org.gephi.tools.spi.Tool)

Example 23 with ChangeEvent

use of javax.swing.event.ChangeEvent in project gephi by gephi.

the class SelectionBar method createPopup.

public JPopupMenu createPopup() {
    SelectionManager manager = VizController.getInstance().getSelectionManager();
    final MouseSelectionPopupPanel popupPanel = new MouseSelectionPopupPanel();
    popupPanel.setDiameter(manager.getMouseSelectionDiameter());
    popupPanel.setProportionnalToZoom(manager.isMouseSelectionZoomProportionnal());
    popupPanel.setChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            SelectionManager manager = VizController.getInstance().getSelectionManager();
            manager.setMouseSelectionDiameter(popupPanel.getDiameter());
            manager.setMouseSelectionZoomProportionnal(popupPanel.isProportionnalToZoom());
        }
    });
    JPopupMenu menu = new JPopupMenu();
    menu.add(popupPanel);
    return menu;
}
Also used : SelectionManager(org.gephi.visualization.api.selection.SelectionManager) ChangeEvent(javax.swing.event.ChangeEvent) ChangeListener(javax.swing.event.ChangeListener) JPopupMenu(javax.swing.JPopupMenu)

Example 24 with ChangeEvent

use of javax.swing.event.ChangeEvent in project gephi by gephi.

the class CreateTimeIntervalUI method buildValidationPanel.

private void buildValidationPanel() {
    validationPanel = new ValidationPanel();
    validationPanel.setInnerComponent(this);
    ValidationGroup group = validationPanel.getValidationGroup();
    group.add(dateFormatComboBox, new Validator<String>() {

        @Override
        public boolean validate(Problems prblms, String string, String t) {
            boolean valid = validateDateFormat(t);
            if (!valid) {
                prblms.add(NbBundle.getMessage(CreateTimeIntervalUI.class, "CreateTimeIntervalUI.invalid.dateformat"));
            }
            return valid;
        }
    });
    Validator<String> emptyOrNumberValidator = new Validator<String>() {

        @Override
        public boolean validate(Problems prblms, String string, String t) {
            boolean valid = validateNumberOrEmpty(t);
            if (!valid) {
                prblms.add(NbBundle.getMessage(CreateTimeIntervalUI.class, "CreateTimeIntervalUI.invalid.number"));
            }
            return valid;
        }
    };
    group.add(defaultStartNumberText, emptyOrNumberValidator);
    group.add(defaultEndNumberText, emptyOrNumberValidator);
    validationPanel.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            refreshOkButton();
        }
    });
}
Also used : Problems(org.netbeans.validation.api.Problems) ChangeEvent(javax.swing.event.ChangeEvent) ValidationGroup(org.netbeans.validation.api.ui.ValidationGroup) ChangeListener(javax.swing.event.ChangeListener) ValidationPanel(org.netbeans.validation.api.ui.ValidationPanel) Validator(org.netbeans.validation.api.Validator)

Example 25 with ChangeEvent

use of javax.swing.event.ChangeEvent in project binnavi by google.

the class ArrayTypePanel method createControls.

private void createControls() {
    setLayout(new BorderLayout());
    final JPanel contentPanel = new JPanel();
    contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    add(contentPanel, BorderLayout.CENTER);
    final GridBagLayout gbl_m_contentPanel = new GridBagLayout();
    gbl_m_contentPanel.columnWidths = new int[] { 0, 0, 0 };
    gbl_m_contentPanel.rowHeights = new int[] { 0, 0, 0, 0, 0 };
    gbl_m_contentPanel.columnWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
    gbl_m_contentPanel.rowWeights = new double[] { 0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE };
    contentPanel.setLayout(gbl_m_contentPanel);
    final JLabel lblSize = new JLabel("Number of elements:");
    final GridBagConstraints gbc_lblSize = new GridBagConstraints();
    gbc_lblSize.anchor = GridBagConstraints.WEST;
    gbc_lblSize.insets = new Insets(0, 0, 5, 5);
    gbc_lblSize.gridx = 0;
    gbc_lblSize.gridy = 1;
    contentPanel.add(lblSize, gbc_lblSize);
    numberElements = new JSpinner(new SpinnerNumberModel(1, 1, Integer.MAX_VALUE, 1));
    numberElements.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(final ChangeEvent e) {
            updatePreview();
        }
    });
    final GridBagConstraints gbc_numberElements = new GridBagConstraints();
    gbc_numberElements.anchor = GridBagConstraints.WEST;
    gbc_numberElements.insets = new Insets(0, 0, 5, 0);
    gbc_numberElements.gridx = 1;
    gbc_numberElements.gridy = 1;
    contentPanel.add(numberElements, gbc_numberElements);
    final JLabel lblFillWith = new JLabel("Element type:");
    final GridBagConstraints gbc_lblFillWith = new GridBagConstraints();
    gbc_lblFillWith.anchor = GridBagConstraints.WEST;
    gbc_lblFillWith.insets = new Insets(0, 0, 5, 5);
    gbc_lblFillWith.gridx = 0;
    gbc_lblFillWith.gridy = 0;
    contentPanel.add(lblFillWith, gbc_lblFillWith);
    baseTypes = new TypeComboBox(new TypeListModel(typeManager.getTypes(), new TypeListModel.PrototypesFilter()));
    baseTypes.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            updatePreview();
        }
    });
    final GridBagConstraints gbc_baseTypes = new GridBagConstraints();
    gbc_baseTypes.insets = new Insets(0, 0, 5, 0);
    gbc_baseTypes.fill = GridBagConstraints.HORIZONTAL;
    gbc_baseTypes.gridx = 1;
    gbc_baseTypes.gridy = 0;
    contentPanel.add(baseTypes, gbc_baseTypes);
    final JLabel lblPreview = new JLabel("Preview:");
    final GridBagConstraints gbc_lblPreview = new GridBagConstraints();
    gbc_lblPreview.anchor = GridBagConstraints.WEST;
    gbc_lblPreview.insets = new Insets(0, 0, 5, 5);
    gbc_lblPreview.gridx = 0;
    gbc_lblPreview.gridy = 2;
    contentPanel.add(lblPreview, gbc_lblPreview);
    final JScrollPane scrollPane = new JScrollPane();
    scrollPane.setBorder(null);
    final GridBagConstraints gbc_scrollPane = new GridBagConstraints();
    gbc_scrollPane.insets = new Insets(0, 0, 5, 0);
    gbc_scrollPane.fill = GridBagConstraints.BOTH;
    gbc_scrollPane.gridx = 1;
    gbc_scrollPane.gridy = 2;
    contentPanel.add(scrollPane, gbc_scrollPane);
    preview = new JTextArea();
    preview.setEditable(false);
    scrollPane.setViewportView(preview);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) JTextArea(javax.swing.JTextArea) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JLabel(javax.swing.JLabel) SpinnerNumberModel(javax.swing.SpinnerNumberModel) BorderLayout(java.awt.BorderLayout) ChangeEvent(javax.swing.event.ChangeEvent) ActionListener(java.awt.event.ActionListener) JSpinner(javax.swing.JSpinner) ChangeListener(javax.swing.event.ChangeListener) EmptyBorder(javax.swing.border.EmptyBorder)

Aggregations

ChangeEvent (javax.swing.event.ChangeEvent)164 ChangeListener (javax.swing.event.ChangeListener)130 JPanel (javax.swing.JPanel)45 ActionEvent (java.awt.event.ActionEvent)43 ActionListener (java.awt.event.ActionListener)38 JLabel (javax.swing.JLabel)30 GridBagConstraints (java.awt.GridBagConstraints)18 JButton (javax.swing.JButton)17 BorderLayout (java.awt.BorderLayout)16 JCheckBox (javax.swing.JCheckBox)16 JSpinner (javax.swing.JSpinner)16 SpinnerNumberModel (javax.swing.SpinnerNumberModel)16 GridBagLayout (java.awt.GridBagLayout)15 Dimension (java.awt.Dimension)14 PropertyChangeEvent (java.beans.PropertyChangeEvent)14 JSlider (javax.swing.JSlider)14 Insets (java.awt.Insets)13 ValidationPanel (org.netbeans.validation.api.ui.ValidationPanel)13 IOException (java.io.IOException)12 JTabbedPane (javax.swing.JTabbedPane)12