26
26
import javax .swing .JButton ;
27
27
import javax .swing .JCheckBox ;
28
28
import javax .swing .JLabel ;
29
+ import javax .swing .JMenuItem ;
29
30
import javax .swing .JPanel ;
31
+ import javax .swing .JPopupMenu ;
30
32
import javax .swing .JScrollPane ;
31
33
import javax .swing .JTable ;
32
34
import javax .swing .JTextField ;
47
49
import org .cytoscape .service .util .CyServiceRegistrar ;
48
50
import org .cytoscape .util .swing .IconManager ;
49
51
import org .cytoscape .util .swing .LookAndFeelUtil ;
50
-
52
+
51
53
@ SuppressWarnings ("serial" )
52
54
public class DataSetSelector extends JPanel {
53
55
56
+ public static final String PROP_CHECKED_DATA_SETS = "checkedData" ;
57
+
58
+
54
59
private static final String [] HEARDER_NAMES = new String []{ "" , "" , "Name" , "" };
55
60
56
61
private static final int SELECTED_COL_IDX = 0 ;
@@ -62,10 +67,17 @@ public class DataSetSelector extends JPanel {
62
67
63
68
private JTable table ;
64
69
private JScrollPane tableScrollPane ;
65
- private JButton addButton ;
66
- private JButton colorButton ;
67
- private JButton selectAllButton ;
68
- private JButton selectNoneButton ;
70
+ private JMenuItem addMenuItem ;
71
+ private JMenuItem colorMenuItem ;
72
+ private JMenuItem selectAllMenuItem ;
73
+ private JMenuItem selectNoneMenuItem ;
74
+ private JMenuItem selectNodesMenuItem ;
75
+ private JMenuItem deleteSignatureMenuItem ;
76
+ // private JButton addButton;
77
+ // private JButton colorButton;
78
+ // private JButton selectAllButton;
79
+ // private JButton selectNoneButton;
80
+ private JButton optionButton ;
69
81
70
82
private final EnrichmentMap map ;
71
83
@@ -137,7 +149,7 @@ public void setCheckedItems(Set<AbstractDataSet> newValue) {
137
149
138
150
getTable ().repaint ();
139
151
updateSelectionButtons ();
140
- firePropertyChange ("checkedData" , oldValue , getCheckedItems ());
152
+ firePropertyChange (PROP_CHECKED_DATA_SETS , oldValue , getCheckedItems ());
141
153
}
142
154
143
155
public Set <AbstractDataSet > getSelectedItems () {
@@ -156,8 +168,6 @@ private void init() {
156
168
JLabel titleLabel = new JLabel ("Data Sets:" );
157
169
makeSmall (titleLabel );
158
170
159
- LookAndFeelUtil .equalizeSize (getSelectAllButton (), getSelectNoneButton ());
160
-
161
171
final int rh = getTable ().getRowHeight () + 2 ;
162
172
163
173
final GroupLayout layout = new GroupLayout (this );
@@ -168,26 +178,16 @@ private void init() {
168
178
layout .setHorizontalGroup (layout .createParallelGroup (CENTER , true )
169
179
.addGroup (layout .createSequentialGroup ()
170
180
.addComponent (titleLabel , DEFAULT_SIZE , DEFAULT_SIZE , Short .MAX_VALUE )
171
- .addComponent (getSelectAllButton (), PREFERRED_SIZE , DEFAULT_SIZE , PREFERRED_SIZE )
172
- .addComponent (getSelectNoneButton (), PREFERRED_SIZE , DEFAULT_SIZE , PREFERRED_SIZE )
181
+ .addComponent (getOptionsButton (), PREFERRED_SIZE , DEFAULT_SIZE , PREFERRED_SIZE )
173
182
)
174
183
.addComponent (getTableScrollPane (), DEFAULT_SIZE , DEFAULT_SIZE , Short .MAX_VALUE )
175
- .addGroup (layout .createSequentialGroup ()
176
- .addComponent (getDataSetColorButton (), PREFERRED_SIZE , DEFAULT_SIZE , PREFERRED_SIZE )
177
- .addComponent (getAddButton (), PREFERRED_SIZE , DEFAULT_SIZE , PREFERRED_SIZE )
178
- )
179
184
);
180
185
layout .setVerticalGroup (layout .createSequentialGroup ()
181
186
.addGroup (layout .createParallelGroup (CENTER , false )
182
187
.addComponent (titleLabel , PREFERRED_SIZE , DEFAULT_SIZE , PREFERRED_SIZE )
183
- .addComponent (getSelectAllButton (), PREFERRED_SIZE , DEFAULT_SIZE , PREFERRED_SIZE )
184
- .addComponent (getSelectNoneButton (), PREFERRED_SIZE , DEFAULT_SIZE , PREFERRED_SIZE )
188
+ .addComponent (getOptionsButton (), PREFERRED_SIZE , DEFAULT_SIZE , PREFERRED_SIZE )
185
189
)
186
190
.addComponent (getTableScrollPane (), rh * 2 , rh * 3 , Short .MAX_VALUE )
187
- .addGroup (layout .createParallelGroup (CENTER , false )
188
- .addComponent (getDataSetColorButton (), PREFERRED_SIZE , DEFAULT_SIZE , PREFERRED_SIZE )
189
- .addComponent (getAddButton (), PREFERRED_SIZE , DEFAULT_SIZE , PREFERRED_SIZE )
190
- )
191
191
);
192
192
193
193
if (isAquaLAF ())
@@ -243,8 +243,8 @@ private void updateSelectionButtons() {
243
243
break ;
244
244
}
245
245
246
- getSelectAllButton ().setEnabled (hasUnchecked );
247
- getSelectNoneButton ().setEnabled (hasChecked );
246
+ getSelectAllMenuItem ().setEnabled (hasUnchecked );
247
+ getSelectNoneMenuItem ().setEnabled (hasChecked );
248
248
}
249
249
250
250
JTable getTable () {
@@ -276,6 +276,7 @@ public TableCellRenderer getCellRenderer(int row, int column) {
276
276
previousSelectedRows = Arrays .stream (table .getSelectedRows ()).boxed ().collect (Collectors .toList ());
277
277
}
278
278
});
279
+
279
280
table .addMouseListener (new MouseAdapter () {
280
281
@ Override
281
282
public void mousePressed (MouseEvent e ) {
@@ -333,52 +334,94 @@ public void mousePressed(MouseEvent e) {
333
334
return tableScrollPane ;
334
335
}
335
336
336
- JButton getAddButton () {
337
- if (addButton == null ) {
338
- addButton = new JButton (PADialogMediator .NAME );
339
- addButton .setToolTipText ("Post Analysis" );
340
- makeSmall (addButton );
341
- if (isAquaLAF ())
342
- addButton .putClientProperty ("JButton.buttonType" , "gradient" );
337
+ JMenuItem getAddMenuItem () {
338
+ if (addMenuItem == null ) {
339
+ addMenuItem = new JMenuItem (PADialogMediator .NAME );
343
340
}
344
- return addButton ;
341
+ return addMenuItem ;
345
342
}
346
343
347
- JButton getDataSetColorButton () {
348
- if (colorButton == null ) {
349
- colorButton = new JButton ("Change Colors..." );
350
- colorButton .setToolTipText ("Change data set colors" );
351
- makeSmall (colorButton );
352
- if (isAquaLAF ())
353
- colorButton .putClientProperty ("JButton.buttonType" , "gradient" );
344
+ JMenuItem getDataSetColorMenuItem () {
345
+ if (colorMenuItem == null ) {
346
+ colorMenuItem = new JMenuItem ("Change data set colors..." );
354
347
}
355
- return colorButton ;
348
+ return colorMenuItem ;
356
349
}
357
350
358
- JButton getSelectAllButton () {
359
- if (selectAllButton == null ) {
360
- selectAllButton = new JButton ("Select All" );
361
- selectAllButton .addActionListener (evt -> {
351
+ JMenuItem getSelectAllMenuItem () {
352
+ if (selectAllMenuItem == null ) {
353
+ selectAllMenuItem = new JMenuItem ("Select All" );
354
+ selectAllMenuItem .addActionListener (evt -> {
362
355
setCheckedToAllRows (true );
363
356
});
364
- makeSmall (selectAllButton );
365
- if (isAquaLAF ())
366
- selectAllButton .putClientProperty ("JButton.buttonType" , "gradient" );
367
357
}
368
- return selectAllButton ;
358
+ return selectAllMenuItem ;
369
359
}
370
360
371
- JButton getSelectNoneButton () {
372
- if (selectNoneButton == null ) {
373
- selectNoneButton = new JButton ("Select None" );
374
- selectNoneButton .addActionListener (evt -> {
361
+ JMenuItem getSelectNoneMenuItem () {
362
+ if (selectNoneMenuItem == null ) {
363
+ selectNoneMenuItem = new JMenuItem ("Select None" );
364
+ selectNoneMenuItem .addActionListener (evt -> {
375
365
setCheckedToAllRows (false );
376
366
});
377
- makeSmall (selectNoneButton );
367
+ }
368
+ return selectNoneMenuItem ;
369
+ }
370
+
371
+ JMenuItem getSelectNodesMenuItem () {
372
+ if (selectNodesMenuItem == null ) {
373
+ selectNodesMenuItem = new JMenuItem ("Select nodes and edges from selected data sets" );
374
+ }
375
+ return selectNodesMenuItem ;
376
+ }
377
+
378
+ JMenuItem getDeleteSignatureMenuItem () {
379
+ if (deleteSignatureMenuItem == null ) {
380
+ deleteSignatureMenuItem = new JMenuItem ("Remove selected signature gene sets" );
381
+ }
382
+ return deleteSignatureMenuItem ;
383
+ }
384
+
385
+ JButton getOptionsButton () {
386
+ if (optionButton == null ) {
387
+ optionButton = new JButton ("Options..." );
388
+ makeSmall (optionButton );
378
389
if (isAquaLAF ())
379
- selectNoneButton .putClientProperty ("JButton.buttonType" , "gradient" );
390
+ optionButton .putClientProperty ("JButton.buttonType" , "gradient" );
391
+
392
+ optionButton .addActionListener (e -> {
393
+ getOptionsMenu ().show (optionButton , 0 , optionButton .getHeight ());
394
+ });
395
+ }
396
+ return optionButton ;
397
+ }
398
+
399
+ private JPopupMenu getOptionsMenu () {
400
+ JPopupMenu menu = new JPopupMenu ();
401
+ menu .add (getAddMenuItem ());
402
+ menu .add (getDataSetColorMenuItem ());
403
+ menu .addSeparator ();
404
+ menu .add (getSelectAllMenuItem ());
405
+ menu .add (getSelectNoneMenuItem ());
406
+ menu .addSeparator ();
407
+ menu .add (getSelectNodesMenuItem ());
408
+ menu .add (getDeleteSignatureMenuItem ());
409
+
410
+ getDeleteSignatureMenuItem ().setEnabled (isOnlySignatureSelected ());
411
+
412
+ return menu ;
413
+ }
414
+
415
+ private boolean isOnlySignatureSelected () {
416
+ Set <AbstractDataSet > selected = getSelectedItems ();
417
+ boolean onlySignatureSelected = !selected .isEmpty ();
418
+ for (AbstractDataSet ds : selected ) {
419
+ if (ds instanceof EMSignatureDataSet == false ) {
420
+ onlySignatureSelected = false ;
421
+ break ;
422
+ }
380
423
}
381
- return selectNoneButton ;
424
+ return onlySignatureSelected ;
382
425
}
383
426
384
427
private void setCheckedToAllRows (final boolean checked ) {
@@ -393,7 +436,7 @@ private void setCheckedToAllRows(final boolean checked) {
393
436
394
437
getTable ().repaint ();
395
438
updateSelectionButtons ();
396
- firePropertyChange ("checkedData" , oldValue , getCheckedItems ());
439
+ firePropertyChange (PROP_CHECKED_DATA_SETS , oldValue , getCheckedItems ());
397
440
}
398
441
399
442
private void toggleChecked (final int row ) {
@@ -410,7 +453,7 @@ private void toggleChecked(final int row) {
410
453
411
454
getTable ().repaint ();
412
455
updateSelectionButtons ();
413
- firePropertyChange ("checkedData" , oldValue , getCheckedItems ());
456
+ firePropertyChange (PROP_CHECKED_DATA_SETS , oldValue , getCheckedItems ());
414
457
}
415
458
}
416
459
0 commit comments