Search in sources :

Example 71 with ActionEvent

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

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

Example 73 with ActionEvent

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

the class ActionsToolbar method initContent.

private void initContent() {
    //Center on graph
    final JButton centerOnGraphButton = new JButton();
    centerOnGraphButton.setToolTipText(NbBundle.getMessage(VizBarController.class, "ActionsToolbar.centerOnGraph"));
    centerOnGraphButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/gephi/visualization/component/centerOnGraph.png")));
    centerOnGraphButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            VizController.getInstance().getGraphIO().centerOnGraph();
        }
    });
    add(centerOnGraphButton);
    //Center on zero
    /*final JButton centerOnZeroButton = new JButton();
         centerOnZeroButton.setToolTipText(NbBundle.getMessage(VizBarController.class, "ActionsToolbar.centerOnZero"));
         centerOnZeroButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/gephi/visualization/component/centerOnZero.png")));
         centerOnZeroButton.addActionListener(new ActionListener() {

         public void actionPerformed(ActionEvent e) {
         VizController.getInstance().getGraphIO().centerOnZero();
         }
         });
         add(centerOnZeroButton);*/
    //Reset colors
    final JColorButton resetColorButton = new JColorButton(color, true, false);
    resetColorButton.setToolTipText(NbBundle.getMessage(ActionsToolbar.class, "ActionsToolbar.resetColors"));
    resetColorButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            color = resetColorButton.getColor();
            GraphController gc = Lookup.getDefault().lookup(GraphController.class);
            GraphModel gm = gc.getGraphModel();
            Graph graph = gm.getGraphVisible();
            for (Node n : graph.getNodes()) {
                n.setR(color.getRed() / 255f);
                n.setG(color.getGreen() / 255f);
                n.setB(color.getBlue() / 255f);
                n.setAlpha(1f);
            }
            for (Edge e : graph.getEdges()) {
                e.setR(color.getRed() / 255f);
                e.setG(color.getGreen() / 255f);
                e.setB(color.getBlue() / 255f);
                e.setAlpha(0f);
            }
        }
    });
    add(resetColorButton);
    //Reset sizes
    //Reset label colors
    final JButton resetLabelColorButton = new JButton();
    resetLabelColorButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/gephi/visualization/component/resetLabelColor.png")));
    resetLabelColorButton.setToolTipText(NbBundle.getMessage(ActionsToolbar.class, "ActionsToolbar.resetLabelColors"));
    resetLabelColorButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            GraphController gc = Lookup.getDefault().lookup(GraphController.class);
            GraphModel gm = gc.getGraphModel();
            Graph graph = gm.getGraphVisible();
            for (Node n : graph.getNodes().toArray()) {
                n.getTextProperties().setColor(Color.BLACK);
                n.getTextProperties().setAlpha(0f);
            }
            for (Edge e : graph.getEdges().toArray()) {
                e.getTextProperties().setColor(Color.BLACK);
                e.getTextProperties().setAlpha(0f);
            }
        }
    });
    add(resetLabelColorButton);
    //Reset label visible
    final JButton resetLabelVisibleButton = new JButton();
    resetLabelVisibleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/gephi/visualization/component/resetLabelVisible.png")));
    resetLabelVisibleButton.setToolTipText(NbBundle.getMessage(ActionsToolbar.class, "ActionsToolbar.resetLabelVisible"));
    resetLabelVisibleButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            GraphController gc = Lookup.getDefault().lookup(GraphController.class);
            GraphModel gm = gc.getGraphModel();
            Graph graph = gm.getGraphVisible();
            for (Node n : graph.getNodes()) {
                n.getTextProperties().setVisible(true);
            }
            for (Edge e : graph.getEdges()) {
                e.getTextProperties().setVisible(true);
            }
        }
    });
    add(resetLabelVisibleButton);
}
Also used : ActionEvent(java.awt.event.ActionEvent) Node(org.gephi.graph.api.Node) JButton(javax.swing.JButton) JColorButton(org.gephi.ui.components.JColorButton) Graph(org.gephi.graph.api.Graph) ActionListener(java.awt.event.ActionListener) GraphModel(org.gephi.graph.api.GraphModel) Edge(org.gephi.graph.api.Edge) GraphController(org.gephi.graph.api.GraphController)

Example 74 with ActionEvent

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

the class EdgeSettingsPanel method setup.

public void setup() {
    VizModel vizModel = VizController.getInstance().getVizModel();
    vizModel.addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals("init")) {
                refreshSharedConfig();
            } else if (evt.getPropertyName().equals("edgeHasUniColor")) {
                refreshSharedConfig();
            } else if (evt.getPropertyName().equals("showEdges")) {
                refreshSharedConfig();
            } else if (evt.getPropertyName().equals("edgeUniColor")) {
                refreshSharedConfig();
            } else if (evt.getPropertyName().equals("edgeSelectionColor")) {
                refreshSharedConfig();
            } else if (evt.getPropertyName().equals("edgeInSelectionColor")) {
                refreshSharedConfig();
            } else if (evt.getPropertyName().equals("edgeOutSelectionColor")) {
                refreshSharedConfig();
            } else if (evt.getPropertyName().equals("edgeBothSelectionColor")) {
                refreshSharedConfig();
            } else if (evt.getPropertyName().equals("edgeScale")) {
                refreshSharedConfig();
            }
        }
    });
    refreshSharedConfig();
    showEdgesCheckbox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            VizModel vizModel = VizController.getInstance().getVizModel();
            vizModel.setShowEdges(showEdgesCheckbox.isSelected());
            setEnable(true);
        }
    });
    ((JColorButton) edgeColorButton).addPropertyChangeListener(JColorButton.EVENT_COLOR, new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            VizModel vizModel = VizController.getInstance().getVizModel();
            vizModel.setEdgeUniColor(((JColorButton) edgeColorButton).getColorArray());
        }
    });
    sourceNodeColorCheckbox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            VizModel vizModel = VizController.getInstance().getVizModel();
            vizModel.setEdgeHasUniColor(!sourceNodeColorCheckbox.isSelected());
        }
    });
    selectionColorCheckbox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            VizModel vizModel = VizController.getInstance().getVizModel();
            vizModel.setEdgeSelectionColor(selectionColorCheckbox.isSelected());
        }
    });
    edgeInSelectionColorChooser.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            VizModel vizModel = VizController.getInstance().getVizModel();
            vizModel.setEdgeInSelectionColor(edgeInSelectionColorChooser.getColor().getComponents(null));
        }
    });
    edgeBothSelectionColorChooser.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            VizModel vizModel = VizController.getInstance().getVizModel();
            vizModel.setEdgeBothSelectionColor(edgeBothSelectionColorChooser.getColor().getComponents(null));
        }
    });
    edgeOutSelectionColorChooser.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            VizModel vizModel = VizController.getInstance().getVizModel();
            vizModel.setEdgeOutSelectionColor(edgeOutSelectionColorChooser.getColor().getComponents(null));
        }
    });
    scaleSlider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            VizModel vizModel = VizController.getInstance().getVizModel();
            if (vizModel.getEdgeScale() != (scaleSlider.getValue() / 10f + 0.1f)) {
                vizModel.setEdgeScale(scaleSlider.getValue() / 10f + 0.1f);
            }
        }
    });
}
Also used : JColorButton(org.gephi.ui.components.JColorButton) VizModel(org.gephi.visualization.VizModel) PropertyChangeEvent(java.beans.PropertyChangeEvent) ItemEvent(java.awt.event.ItemEvent) PropertyChangeListener(java.beans.PropertyChangeListener) ActionListener(java.awt.event.ActionListener) ChangeEvent(javax.swing.event.ChangeEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) ActionEvent(java.awt.event.ActionEvent) ItemListener(java.awt.event.ItemListener) PropertyChangeListener(java.beans.PropertyChangeListener) ChangeListener(javax.swing.event.ChangeListener)

Example 75 with ActionEvent

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

the class GraphContextMenu method createMenuItemFromGraphContextMenuItem.

public JMenuItem createMenuItemFromGraphContextMenuItem(final GraphContextMenuItem item, final Graph graph, final Node[] nodes) {
    ContextMenuItemManipulator[] subItems = item.getSubItems();
    if (subItems != null && item.canExecute()) {
        JMenu subMenu = new JMenu();
        subMenu.setText(item.getName());
        if (item.getDescription() != null && !item.getDescription().isEmpty()) {
            subMenu.setToolTipText(item.getDescription());
        }
        subMenu.setIcon(item.getIcon());
        Integer lastItemType = null;
        for (ContextMenuItemManipulator subItem : subItems) {
            ((GraphContextMenuItem) subItem).setup(graph, nodes);
            if (lastItemType == null) {
                lastItemType = subItem.getType();
            }
            if (lastItemType != subItem.getType()) {
                subMenu.addSeparator();
            }
            lastItemType = subItem.getType();
            if (subItem.isAvailable()) {
                subMenu.add(createMenuItemFromGraphContextMenuItem((GraphContextMenuItem) subItem, graph, nodes));
            }
        }
        if (item.getMnemonicKey() != null) {
            //Mnemonic for opening a sub menu
            subMenu.setMnemonic(item.getMnemonicKey());
        }
        return subMenu;
    } else {
        JMenuItem menuItem = new JMenuItem();
        menuItem.setText(item.getName());
        if (item.getDescription() != null && !item.getDescription().isEmpty()) {
            menuItem.setToolTipText(item.getDescription());
        }
        menuItem.setIcon(item.getIcon());
        if (item.canExecute()) {
            menuItem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    new Thread() {

                        @Override
                        public void run() {
                            DataLaboratoryHelper.getDefault().executeManipulator(item);
                        }
                    }.start();
                }
            });
        } else {
            menuItem.setEnabled(false);
        }
        if (item.getMnemonicKey() != null) {
            //Mnemonic for executing the action
            menuItem.setMnemonic(item.getMnemonicKey());
            //And the same key mnemonic + ctrl for executing the action (and as a help display for the user!).
            menuItem.setAccelerator(KeyStroke.getKeyStroke(item.getMnemonicKey(), KeyEvent.CTRL_DOWN_MASK));
        }
        return menuItem;
    }
}
Also used : GraphContextMenuItem(org.gephi.visualization.spi.GraphContextMenuItem) ContextMenuItemManipulator(org.gephi.datalab.spi.ContextMenuItemManipulator) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu)

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