Search in sources :

Example 1 with Tool

use of org.gephi.tools.spi.Tool 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 2 with Tool

use of org.gephi.tools.spi.Tool in project gephi by gephi.

the class ShortestPath method getUI.

@Override
public ToolUI getUI() {
    return new ToolUI() {

        @Override
        public JPanel getPropertiesBar(Tool tool) {
            shortestPathPanel = new ShortestPathPanel();
            shortestPathPanel.setColor(color);
            shortestPathPanel.setStatus(NbBundle.getMessage(ShortestPath.class, "ShortestPath.status1"));
            return shortestPathPanel;
        }

        @Override
        public String getName() {
            return NbBundle.getMessage(ShortestPath.class, "ShortestPath.name");
        }

        @Override
        public Icon getIcon() {
            return new ImageIcon(getClass().getResource("/org/gephi/tools/plugin/resources/shortestpath.png"));
        }

        @Override
        public String getDescription() {
            return NbBundle.getMessage(ShortestPath.class, "ShortestPath.description");
        }

        @Override
        public int getPosition() {
            return 140;
        }
    };
}
Also used : ImageIcon(javax.swing.ImageIcon) ToolUI(org.gephi.tools.spi.ToolUI) ShortestPathPanel(org.gephi.ui.tools.plugin.ShortestPathPanel) Tool(org.gephi.tools.spi.Tool)

Example 3 with Tool

use of org.gephi.tools.spi.Tool in project gephi by gephi.

the class Brush method getUI.

@Override
public ToolUI getUI() {
    return new ToolUI() {

        @Override
        public JPanel getPropertiesBar(Tool tool) {
            brushPanel = new BrushPanel();
            brushPanel.setDiffusionMethod(diffusionMethod);
            brushPanel.setColor(new Color(color[0], color[1], color[2]));
            brushPanel.setIntensity(intensity);
            return brushPanel;
        }

        @Override
        public String getName() {
            return NbBundle.getMessage(Brush.class, "Brush.name");
        }

        @Override
        public Icon getIcon() {
            return new ImageIcon(getClass().getResource("/org/gephi/tools/plugin/resources/brush.png"));
        }

        @Override
        public String getDescription() {
            return NbBundle.getMessage(Painter.class, "Brush.description");
        }

        @Override
        public int getPosition() {
            return 110;
        }
    };
}
Also used : BrushPanel(org.gephi.ui.tools.plugin.BrushPanel) ImageIcon(javax.swing.ImageIcon) Color(java.awt.Color) ToolUI(org.gephi.tools.spi.ToolUI) Tool(org.gephi.tools.spi.Tool)

Example 4 with Tool

use of org.gephi.tools.spi.Tool in project gephi by gephi.

the class NodePencil method getUI.

@Override
public ToolUI getUI() {
    return new ToolUI() {

        @Override
        public JPanel getPropertiesBar(Tool tool) {
            nodePencilPanel = new NodePencilPanel();
            nodePencilPanel.setColor(color);
            nodePencilPanel.setNodeSize(size);
            return nodePencilPanel;
        }

        @Override
        public String getName() {
            return NbBundle.getMessage(NodePencil.class, "NodePencil.name");
        }

        @Override
        public Icon getIcon() {
            return new ImageIcon(getClass().getResource("/org/gephi/tools/plugin/resources/nodepencil.png"));
        }

        @Override
        public String getDescription() {
            return NbBundle.getMessage(NodePencil.class, "NodePencil.description");
        }

        @Override
        public int getPosition() {
            return 120;
        }
    };
}
Also used : NodePencilPanel(org.gephi.ui.tools.plugin.NodePencilPanel) ImageIcon(javax.swing.ImageIcon) ToolUI(org.gephi.tools.spi.ToolUI) Tool(org.gephi.tools.spi.Tool)

Example 5 with Tool

use of org.gephi.tools.spi.Tool in project gephi by gephi.

the class EdgePencil method getUI.

@Override
public ToolUI getUI() {
    return new ToolUI() {

        @Override
        public JPanel getPropertiesBar(Tool tool) {
            edgePencilPanel = new EdgePencilPanel();
            edgePencilPanel.setColor(color);
            edgePencilPanel.setWeight(weight);
            updatePanel();
            return edgePencilPanel;
        }

        @Override
        public String getName() {
            return NbBundle.getMessage(EdgePencil.class, "EdgePencil.name");
        }

        @Override
        public Icon getIcon() {
            return new ImageIcon(getClass().getResource("/org/gephi/tools/plugin/resources/edgepencil.png"));
        }

        @Override
        public String getDescription() {
            return NbBundle.getMessage(EdgePencil.class, "EdgePencil.description");
        }

        @Override
        public int getPosition() {
            return 130;
        }
    };
}
Also used : ImageIcon(javax.swing.ImageIcon) EdgePencilPanel(org.gephi.ui.tools.plugin.EdgePencilPanel) ToolUI(org.gephi.tools.spi.ToolUI) Tool(org.gephi.tools.spi.Tool)

Aggregations

ImageIcon (javax.swing.ImageIcon)6 Tool (org.gephi.tools.spi.Tool)6 ToolUI (org.gephi.tools.spi.ToolUI)6 Color (java.awt.Color)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 JToggleButton (javax.swing.JToggleButton)1 ChangeEvent (javax.swing.event.ChangeEvent)1 ChangeListener (javax.swing.event.ChangeListener)1 UnselectToolException (org.gephi.tools.spi.UnselectToolException)1 BrushPanel (org.gephi.ui.tools.plugin.BrushPanel)1 EdgePencilPanel (org.gephi.ui.tools.plugin.EdgePencilPanel)1 NodePencilPanel (org.gephi.ui.tools.plugin.NodePencilPanel)1 PainterPanel (org.gephi.ui.tools.plugin.PainterPanel)1 ShortestPathPanel (org.gephi.ui.tools.plugin.ShortestPathPanel)1 SelectionManager (org.gephi.visualization.api.selection.SelectionManager)1