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);
}
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);
}
}
});
}
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;
}
}
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;
}
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;
}
Aggregations