Search in sources :

Example 66 with ActionListener

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

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

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

Example 69 with ActionListener

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

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

the class PropertiesBar method getFullScreenIcon.

private JComponent getFullScreenIcon() {
    int logoWidth = 27;
    int logoHeight = 28;
    //fullscreen icon size
    if (UIUtils.isAquaLookAndFeel()) {
        logoWidth = 34;
    }
    JPanel c = new JPanel(new BorderLayout());
    c.setBackground(Color.WHITE);
    JButton fullScreenButton = new JButton();
    fullScreenButton.setIcon(new ImageIcon(getClass().getResource("/org/gephi/desktop/tools/gephilogo_std.png")));
    fullScreenButton.setRolloverEnabled(true);
    fullScreenButton.setRolloverIcon(new ImageIcon(getClass().getResource("/org/gephi/desktop/tools/gephilogo_glow.png")));
    fullScreenButton.setToolTipText(NbBundle.getMessage(PropertiesBar.class, "PropertiesBar.fullScreenButton.tooltip"));
    fullScreenButton.setBorderPainted(false);
    fullScreenButton.setContentAreaFilled(false);
    fullScreenButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    fullScreenButton.setBorder(BorderFactory.createEmptyBorder());
    fullScreenButton.setPreferredSize(new Dimension(logoWidth, logoHeight));
    fullScreenButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Lookup lookup = Lookups.forPath("org-gephi-desktop-tools/Actions/ToggleFullScreenAction");
            for (Action a : lookup.lookupAll(Action.class)) {
                a.actionPerformed(null);
            }
        }
    });
    c.add(fullScreenButton, BorderLayout.CENTER);
    return c;
}
Also used : JPanel(javax.swing.JPanel) ImageIcon(javax.swing.ImageIcon) Action(javax.swing.Action) BorderLayout(java.awt.BorderLayout) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) Lookup(org.openide.util.Lookup) Dimension(java.awt.Dimension)

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