| 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.cytoscape; |
| 25 | |
|
| 26 | |
import java.awt.BorderLayout; |
| 27 | |
import java.awt.Toolkit; |
| 28 | |
|
| 29 | |
import java.awt.event.ActionEvent; |
| 30 | |
import java.awt.event.InputEvent; |
| 31 | |
import java.awt.event.KeyEvent; |
| 32 | |
|
| 33 | |
import javax.swing.AbstractAction; |
| 34 | |
import javax.swing.Action; |
| 35 | |
import javax.swing.InputMap; |
| 36 | |
import javax.swing.KeyStroke; |
| 37 | |
import javax.swing.JComponent; |
| 38 | |
import javax.swing.JMenuItem; |
| 39 | |
import javax.swing.JPanel; |
| 40 | |
import javax.swing.JPopupMenu; |
| 41 | |
|
| 42 | |
import javax.swing.border.EmptyBorder; |
| 43 | |
|
| 44 | |
import cytoscape.CyNode; |
| 45 | |
import cytoscape.CyNetwork; |
| 46 | |
import cytoscape.Cytoscape; |
| 47 | |
|
| 48 | |
import org.dishevelled.identify.ContextMenuListener; |
| 49 | |
import org.dishevelled.identify.IdToolBar; |
| 50 | |
|
| 51 | |
import org.dishevelled.observable.event.SetChangeEvent; |
| 52 | |
import org.dishevelled.observable.event.SetChangeListener; |
| 53 | |
|
| 54 | |
import org.dishevelled.venn.cytoscape.CyNodeListCellRenderer; |
| 55 | |
import org.dishevelled.venn.swing.BinaryVennList; |
| 56 | |
import org.dishevelled.venn.swing.TernaryVennList; |
| 57 | |
import org.dishevelled.venn.swing.QuaternaryVennList; |
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | 0 | final class DetailsView |
| 65 | |
extends JPanel |
| 66 | |
{ |
| 67 | |
|
| 68 | 0 | private final int BINARY_SELECTION_SYNC_MAXIMUM = Integer.MAX_VALUE; |
| 69 | |
|
| 70 | |
|
| 71 | 0 | private final int TERNARY_SELECTION_SYNC_MAXIMUM = 2000000; |
| 72 | |
|
| 73 | |
|
| 74 | 0 | private final int QUATERNARY_SELECTION_SYNC_MAXIMUM = 20000; |
| 75 | |
|
| 76 | |
|
| 77 | |
private final BinaryVennList<CyNode> binaryVennList; |
| 78 | |
|
| 79 | |
|
| 80 | |
private final TernaryVennList<CyNode> ternaryVennList; |
| 81 | |
|
| 82 | |
|
| 83 | |
private final QuaternaryVennList<CyNode> quaternaryVennList; |
| 84 | |
|
| 85 | |
|
| 86 | 0 | private final SetChangeListener<CyNode> updateCytoscapeSelection = new SetChangeListener<CyNode>() |
| 87 | 0 | { |
| 88 | |
|
| 89 | |
public void setChanged(final SetChangeEvent<CyNode> event) |
| 90 | |
{ |
| 91 | |
|
| 92 | 0 | CyNetwork currentNetwork = Cytoscape.getCurrentNetwork(); |
| 93 | 0 | currentNetwork.unselectAllNodes(); |
| 94 | 0 | currentNetwork.setSelectedNodeState(event.getObservableSet(), true); |
| 95 | 0 | Cytoscape.getCurrentNetworkView().updateView(); |
| 96 | 0 | } |
| 97 | |
}; |
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | 0 | private final Action selectAll = new AbstractAction("Select all") |
| 103 | 0 | { |
| 104 | |
|
| 105 | |
public void actionPerformed(final ActionEvent event) |
| 106 | |
{ |
| 107 | 0 | if (binaryVennList != null) |
| 108 | |
{ |
| 109 | 0 | binaryVennList.selectAll(); |
| 110 | |
} |
| 111 | 0 | if (ternaryVennList != null) |
| 112 | |
{ |
| 113 | 0 | ternaryVennList.selectAll(); |
| 114 | |
} |
| 115 | 0 | if (quaternaryVennList != null) |
| 116 | |
{ |
| 117 | 0 | quaternaryVennList.selectAll(); |
| 118 | |
} |
| 119 | 0 | } |
| 120 | |
}; |
| 121 | |
|
| 122 | |
|
| 123 | 0 | private final Action clearSelection = new AbstractAction("Clear selection") |
| 124 | 0 | { |
| 125 | |
|
| 126 | |
public void actionPerformed(final ActionEvent event) |
| 127 | |
{ |
| 128 | 0 | if (binaryVennList != null) |
| 129 | |
{ |
| 130 | 0 | binaryVennList.clearSelection(); |
| 131 | |
} |
| 132 | 0 | if (ternaryVennList != null) |
| 133 | |
{ |
| 134 | 0 | ternaryVennList.clearSelection(); |
| 135 | |
} |
| 136 | 0 | if (quaternaryVennList != null) |
| 137 | |
{ |
| 138 | 0 | quaternaryVennList.clearSelection(); |
| 139 | |
} |
| 140 | 0 | } |
| 141 | |
}; |
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
private DetailsView(final BinaryVennList<CyNode> binaryVennList, |
| 152 | |
final TernaryVennList<CyNode> ternaryVennList, |
| 153 | |
final QuaternaryVennList<CyNode> quaternaryVennList) |
| 154 | |
{ |
| 155 | 0 | super(); |
| 156 | 0 | this.binaryVennList = binaryVennList; |
| 157 | 0 | this.ternaryVennList = ternaryVennList; |
| 158 | 0 | this.quaternaryVennList = quaternaryVennList; |
| 159 | |
|
| 160 | |
|
| 161 | 0 | if (this.binaryVennList != null) |
| 162 | |
{ |
| 163 | 0 | this.binaryVennList.getFirst().setCellRenderer(new CyNodeListCellRenderer()); |
| 164 | 0 | this.binaryVennList.getFirstOnly().setCellRenderer(new CyNodeListCellRenderer()); |
| 165 | 0 | this.binaryVennList.getIntersection().setCellRenderer(new CyNodeListCellRenderer()); |
| 166 | 0 | this.binaryVennList.getSecond().setCellRenderer(new CyNodeListCellRenderer()); |
| 167 | 0 | this.binaryVennList.getSecondOnly().setCellRenderer(new CyNodeListCellRenderer()); |
| 168 | 0 | this.binaryVennList.getUnion().setCellRenderer(new CyNodeListCellRenderer()); |
| 169 | |
} |
| 170 | 0 | if (this.ternaryVennList != null) |
| 171 | |
{ |
| 172 | 0 | this.ternaryVennList.getFirst().setCellRenderer(new CyNodeListCellRenderer()); |
| 173 | 0 | this.ternaryVennList.getFirstOnly().setCellRenderer(new CyNodeListCellRenderer()); |
| 174 | 0 | this.ternaryVennList.getFirstSecond().setCellRenderer(new CyNodeListCellRenderer()); |
| 175 | 0 | this.ternaryVennList.getFirstThird().setCellRenderer(new CyNodeListCellRenderer()); |
| 176 | 0 | this.ternaryVennList.getIntersection().setCellRenderer(new CyNodeListCellRenderer()); |
| 177 | 0 | this.ternaryVennList.getSecond().setCellRenderer(new CyNodeListCellRenderer()); |
| 178 | 0 | this.ternaryVennList.getSecondOnly().setCellRenderer(new CyNodeListCellRenderer()); |
| 179 | 0 | this.ternaryVennList.getSecondThird().setCellRenderer(new CyNodeListCellRenderer()); |
| 180 | 0 | this.ternaryVennList.getThird().setCellRenderer(new CyNodeListCellRenderer()); |
| 181 | 0 | this.ternaryVennList.getThirdOnly().setCellRenderer(new CyNodeListCellRenderer()); |
| 182 | 0 | this.ternaryVennList.getUnion().setCellRenderer(new CyNodeListCellRenderer()); |
| 183 | |
} |
| 184 | 0 | if (this.quaternaryVennList != null) |
| 185 | |
{ |
| 186 | 0 | this.quaternaryVennList.getFirst().setCellRenderer(new CyNodeListCellRenderer()); |
| 187 | 0 | this.quaternaryVennList.getFirstFourth().setCellRenderer(new CyNodeListCellRenderer()); |
| 188 | 0 | this.quaternaryVennList.getFirstOnly().setCellRenderer(new CyNodeListCellRenderer()); |
| 189 | 0 | this.quaternaryVennList.getFirstSecond().setCellRenderer(new CyNodeListCellRenderer()); |
| 190 | 0 | this.quaternaryVennList.getFirstSecondFourth().setCellRenderer(new CyNodeListCellRenderer()); |
| 191 | 0 | this.quaternaryVennList.getFirstSecondThird().setCellRenderer(new CyNodeListCellRenderer()); |
| 192 | 0 | this.quaternaryVennList.getFirstThird().setCellRenderer(new CyNodeListCellRenderer()); |
| 193 | 0 | this.quaternaryVennList.getFirstThirdFourth().setCellRenderer(new CyNodeListCellRenderer()); |
| 194 | 0 | this.quaternaryVennList.getFourth().setCellRenderer(new CyNodeListCellRenderer()); |
| 195 | 0 | this.quaternaryVennList.getFourthOnly().setCellRenderer(new CyNodeListCellRenderer()); |
| 196 | 0 | this.quaternaryVennList.getIntersection().setCellRenderer(new CyNodeListCellRenderer()); |
| 197 | 0 | this.quaternaryVennList.getSecond().setCellRenderer(new CyNodeListCellRenderer()); |
| 198 | 0 | this.quaternaryVennList.getSecondFourth().setCellRenderer(new CyNodeListCellRenderer()); |
| 199 | 0 | this.quaternaryVennList.getSecondOnly().setCellRenderer(new CyNodeListCellRenderer()); |
| 200 | 0 | this.quaternaryVennList.getSecondThird().setCellRenderer(new CyNodeListCellRenderer()); |
| 201 | 0 | this.quaternaryVennList.getSecondThirdFourth().setCellRenderer(new CyNodeListCellRenderer()); |
| 202 | 0 | this.quaternaryVennList.getThird().setCellRenderer(new CyNodeListCellRenderer()); |
| 203 | 0 | this.quaternaryVennList.getThirdFourth().setCellRenderer(new CyNodeListCellRenderer()); |
| 204 | 0 | this.quaternaryVennList.getThirdOnly().setCellRenderer(new CyNodeListCellRenderer()); |
| 205 | 0 | this.quaternaryVennList.getUnion().setCellRenderer(new CyNodeListCellRenderer()); |
| 206 | |
} |
| 207 | |
|
| 208 | 0 | InputMap inputMap = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); |
| 209 | 0 | int menuKeyMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); |
| 210 | 0 | KeyStroke ctrlShiftA = KeyStroke.getKeyStroke(KeyEvent.VK_A, menuKeyMask | InputEvent.SHIFT_DOWN_MASK); |
| 211 | 0 | KeyStroke ctrlShiftC = KeyStroke.getKeyStroke(KeyEvent.VK_C, menuKeyMask | InputEvent.SHIFT_DOWN_MASK); |
| 212 | 0 | inputMap.put(ctrlShiftA, "selectAll"); |
| 213 | 0 | inputMap.put(ctrlShiftC, "clearSelection"); |
| 214 | 0 | getActionMap().put("selectAll", selectAll); |
| 215 | 0 | getActionMap().put("clearSelection", clearSelection); |
| 216 | |
|
| 217 | 0 | JMenuItem selectAllMenuItem = new JMenuItem(selectAll); |
| 218 | 0 | selectAllMenuItem.setAccelerator(ctrlShiftA); |
| 219 | 0 | JMenuItem clearSelectionMenuItem = new JMenuItem(clearSelection); |
| 220 | 0 | clearSelectionMenuItem.setAccelerator(ctrlShiftC); |
| 221 | |
|
| 222 | 0 | JPopupMenu contextMenu = new JPopupMenu(); |
| 223 | 0 | contextMenu.add(selectAllMenuItem); |
| 224 | 0 | contextMenu.add(clearSelectionMenuItem); |
| 225 | |
|
| 226 | 0 | IdToolBar toolBar = new IdToolBar(); |
| 227 | |
|
| 228 | 0 | toolBar.add(selectAll); |
| 229 | 0 | toolBar.add(clearSelection); |
| 230 | 0 | toolBar.displayText(); |
| 231 | |
|
| 232 | 0 | setLayout(new BorderLayout()); |
| 233 | 0 | add("North", toolBar); |
| 234 | 0 | addMouseListener(new ContextMenuListener(contextMenu)); |
| 235 | 0 | } |
| 236 | |
|
| 237 | |
|
| 238 | |
|
| 239 | |
|
| 240 | |
|
| 241 | |
|
| 242 | |
DetailsView(final BinaryVennList<CyNode> binaryVennList) |
| 243 | |
{ |
| 244 | 0 | this(binaryVennList, null, null); |
| 245 | 0 | binaryVennList.setBorder(new EmptyBorder(12, 12, 12, 12)); |
| 246 | 0 | if (binaryVennList.getModel().union().size() > BINARY_SELECTION_SYNC_MAXIMUM) |
| 247 | |
{ |
| 248 | 0 | selectAll.setEnabled(false); |
| 249 | 0 | clearSelection.setEnabled(false); |
| 250 | |
} |
| 251 | |
else |
| 252 | |
{ |
| 253 | 0 | binaryVennList.getModel().selection().addSetChangeListener(updateCytoscapeSelection); |
| 254 | |
} |
| 255 | 0 | add("Center", binaryVennList); |
| 256 | 0 | } |
| 257 | |
|
| 258 | |
|
| 259 | |
|
| 260 | |
|
| 261 | |
|
| 262 | |
|
| 263 | |
DetailsView(final TernaryVennList<CyNode> ternaryVennList) |
| 264 | |
{ |
| 265 | 0 | this(null, ternaryVennList, null); |
| 266 | 0 | ternaryVennList.setBorder(new EmptyBorder(12, 12, 12, 12)); |
| 267 | 0 | if (ternaryVennList.getModel().union().size() > TERNARY_SELECTION_SYNC_MAXIMUM) |
| 268 | |
{ |
| 269 | 0 | selectAll.setEnabled(false); |
| 270 | 0 | clearSelection.setEnabled(false); |
| 271 | |
} |
| 272 | |
else |
| 273 | |
{ |
| 274 | 0 | ternaryVennList.getModel().selection().addSetChangeListener(updateCytoscapeSelection); |
| 275 | |
} |
| 276 | 0 | add("Center", ternaryVennList); |
| 277 | 0 | } |
| 278 | |
|
| 279 | |
|
| 280 | |
|
| 281 | |
|
| 282 | |
|
| 283 | |
|
| 284 | |
DetailsView(final QuaternaryVennList<CyNode> quaternaryVennList) |
| 285 | |
{ |
| 286 | 0 | this(null, null, quaternaryVennList); |
| 287 | 0 | quaternaryVennList.setBorder(new EmptyBorder(12, 12, 12, 12)); |
| 288 | 0 | if (quaternaryVennList.getModel().union().size() > QUATERNARY_SELECTION_SYNC_MAXIMUM) |
| 289 | |
{ |
| 290 | 0 | selectAll.setEnabled(false); |
| 291 | 0 | clearSelection.setEnabled(false); |
| 292 | |
} |
| 293 | |
else |
| 294 | |
{ |
| 295 | 0 | quaternaryVennList.getModel().selection().addSetChangeListener(updateCytoscapeSelection); |
| 296 | |
} |
| 297 | 0 | add("Center", quaternaryVennList); |
| 298 | 0 | } |
| 299 | |
} |