Skip to content

Commit 669108c

Browse files
committed
topcat: add CellViewWindow
The "Cell View" is a new drop-down menu option when a user right-clicks on a cell in a TableViewerWindow. It pops open a small window that displays the full contents of that cell, with the idea being that it can be used to read the longer form textual descriptions that are stored in some tables.
1 parent 567488b commit 669108c

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package uk.ac.starlink.topcat;
2+
3+
import java.awt.Component;
4+
import java.awt.Dimension;
5+
import javax.swing.JTextArea;
6+
7+
/**
8+
* Window for defining up a mutually exclusive group of subsets
9+
* based on the values of a given table expression.
10+
*
11+
* @author Fergus Baker
12+
* @since 06 Mar 2026
13+
*/
14+
public class CellViewWindow extends AuxWindow {
15+
String cellString_;
16+
JTextArea textArea_;
17+
18+
/**
19+
* Constructor.
20+
*
21+
* Initialises the Cell View window without any display text.
22+
*
23+
* @param title The title for this window.
24+
* @param parent The parent component.
25+
*/
26+
@SuppressWarnings("this-escape")
27+
public CellViewWindow( String title, Component parent ) {
28+
super(title, parent);
29+
textArea_ = new JTextArea( 5, 25 );
30+
textArea_.setEditable( false );
31+
textArea_.setLineWrap( true );
32+
textArea_.setWrapStyleWord( true );
33+
34+
/* These cause the this-escape warning, but are perfectly safe in this
35+
* context. */
36+
setPreferredSize( new Dimension( 300, 200 ) );
37+
getContentPane().add( textArea_ );
38+
addHelp( null );
39+
}
40+
41+
/**
42+
* Used to set the text to display in the Cell View window.
43+
*
44+
* @param text Text to display in this component.
45+
*/
46+
public void setText( String text ) {
47+
textArea_.selectAll();
48+
textArea_.replaceSelection( text );
49+
}
50+
}

topcat/src/main/uk/ac/starlink/topcat/TableViewerWindow.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,28 @@ private JPopupMenu columnPopup( final int jcol ) {
478478
JPopupMenu popper = new JPopupMenu();
479479
final Component parent = this;
480480

481+
/* Get the current row that is being selected. */
482+
final int jrow = rowSelectionModel_.getMinSelectionIndex();
483+
484+
/* Action to open the cell text in a viewer. */
485+
Action viewCellAct =
486+
new BasicAction( "View Cell", ResourceIcon.ZOOM_IN,
487+
"View the cell contents in a viewer." ) {
488+
public void actionPerformed( ActionEvent evt ) {
489+
CellViewWindow cell_view =
490+
new CellViewWindow( "Cell Viewer", parent );
491+
TableModel tm = jtable_.getModel();
492+
String selectedCell = tm.getValueAt( jrow, jcol ).toString();
493+
cell_view.setText( selectedCell );
494+
cell_view.setVisible( true );
495+
}
496+
};
497+
498+
/* Only enable the Cell View option if something is selected. If no row
499+
* column is selected, it will be displayed in deactived state. */
500+
viewCellAct.setEnabled( jrow >= 0 && jcol >= 0 );
501+
popper.add( viewCellAct );
502+
481503
/* Action to replace current column. */
482504
if ( ! rowHead ) {
483505
Action replacecolAct =

0 commit comments

Comments
 (0)