1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dishevelled.venn.cytoscape3.internal;
25
26 import java.awt.Toolkit;
27
28 import java.awt.event.ActionEvent;
29 import java.awt.event.KeyEvent;
30 import java.awt.event.WindowEvent;
31
32 import javax.swing.AbstractAction;
33 import javax.swing.Action;
34 import javax.swing.KeyStroke;
35 import javax.swing.JComponent;
36 import javax.swing.JDialog;
37 import javax.swing.JRootPane;
38
39 import org.cytoscape.group.CyGroup;
40 import org.cytoscape.model.CyNetwork;
41 import org.cytoscape.model.CyNode;
42 import org.cytoscape.model.CyRow;
43 import org.cytoscape.model.CyTable;
44
45
46
47
48
49
50 final class VennDiagramsUtils
51 {
52
53
54
55
56 private VennDiagramsUtils()
57 {
58
59 }
60
61
62
63
64
65
66
67
68
69 static String nameOf(final CyGroup group, final CyNetwork network)
70 {
71 CyTable nodeTable = network.getDefaultNodeTable();
72 CyRow nodeRow = nodeTable.getRow(group.getGroupNode().getSUID());
73 String name = nodeRow.get(CyNetwork.NAME, String.class);
74 return (name == null) ? group.toString() : name;
75 }
76
77
78
79
80
81
82
83
84 static String nameOf(final CyNode node, final CyNetwork network)
85 {
86 CyTable nodeTable = network.getDefaultNodeTable();
87 CyRow nodeRow = nodeTable.getRow(node.getSUID());
88 String name = nodeRow.get(CyNetwork.NAME, String.class);
89 return (name == null) ? node.toString() : name;
90 }
91
92
93
94
95
96
97
98
99 static void rename(final CyGroup group, final CyNetwork network, final String name)
100 {
101 if (name == null)
102 {
103 return;
104 }
105 CyTable nodeTable = network.getDefaultNodeTable();
106 CyRow nodeRow = nodeTable.getRow(group.getGroupNode().getSUID());
107 nodeRow.set(CyNetwork.NAME, name);
108 }
109
110
111
112
113
114
115 static void installCloseKeyBinding(final JDialog dialog)
116 {
117 Action close = new AbstractAction()
118 {
119
120 public void actionPerformed(final ActionEvent event)
121 {
122 dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING));
123 }
124 };
125 int menuKeyMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
126 KeyStroke closeStroke = KeyStroke.getKeyStroke(KeyEvent.VK_W, menuKeyMask);
127 JRootPane rootPane = dialog.getRootPane();
128 rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(closeStroke, "close");
129 rootPane.getActionMap().put("close", close);
130 }
131 }