Skip to content

Commit 843e5ca

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. The Cell View is displayed at the bottom after a divider, to make it distinct from column operations. When clicked, it pops open a small window that displays the full contents of that cell.
1 parent 567488b commit 843e5ca

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,30 @@ public void actionPerformed( ActionEvent evt ) {
563563
popper.add( explodeAct );
564564
}
565565

566+
popper.addSeparator();
567+
568+
/* Get the current row that is being selected. */
569+
final int jrow = rowSelectionModel_.getMinSelectionIndex();
570+
571+
/* Action to open the cell text in a viewer. */
572+
Action viewCellAct =
573+
new BasicAction( "View Cell", ResourceIcon.ZOOM_IN,
574+
"View the cell contents in a viewer." ) {
575+
public void actionPerformed( ActionEvent evt ) {
576+
CellViewWindow cell_view =
577+
new CellViewWindow( "Cell Viewer", parent );
578+
TableModel tm = jtable_.getModel();
579+
String selectedCell = tm.getValueAt( jrow, jcol ).toString();
580+
cell_view.setText( selectedCell );
581+
cell_view.setVisible( true );
582+
}
583+
};
584+
585+
/* Only enable the Cell View option if something is selected. If no row
586+
* column is selected, it will be displayed in deactived state. */
587+
viewCellAct.setEnabled( jrow >= 0 && jcol >= 0 );
588+
popper.add( viewCellAct );
589+
566590
return popper;
567591
}
568592

0 commit comments

Comments
 (0)