From 843e5ca1c2c9c3e5189a8fef7a3f936f8aa2600a Mon Sep 17 00:00:00 2001 From: fjebaker Date: Wed, 4 Feb 2026 22:16:34 +0000 Subject: [PATCH] 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. --- .../uk/ac/starlink/topcat/CellViewWindow.java | 50 +++++++++++++++++++ .../ac/starlink/topcat/TableViewerWindow.java | 24 +++++++++ 2 files changed, 74 insertions(+) create mode 100644 topcat/src/main/uk/ac/starlink/topcat/CellViewWindow.java diff --git a/topcat/src/main/uk/ac/starlink/topcat/CellViewWindow.java b/topcat/src/main/uk/ac/starlink/topcat/CellViewWindow.java new file mode 100644 index 000000000..46f04b78f --- /dev/null +++ b/topcat/src/main/uk/ac/starlink/topcat/CellViewWindow.java @@ -0,0 +1,50 @@ +package uk.ac.starlink.topcat; + +import java.awt.Component; +import java.awt.Dimension; +import javax.swing.JTextArea; + +/** + * Window for defining up a mutually exclusive group of subsets + * based on the values of a given table expression. + * + * @author Fergus Baker + * @since 06 Mar 2026 + */ +public class CellViewWindow extends AuxWindow { + String cellString_; + JTextArea textArea_; + + /** + * Constructor. + * + * Initialises the Cell View window without any display text. + * + * @param title The title for this window. + * @param parent The parent component. + */ + @SuppressWarnings("this-escape") + public CellViewWindow( String title, Component parent ) { + super(title, parent); + textArea_ = new JTextArea( 5, 25 ); + textArea_.setEditable( false ); + textArea_.setLineWrap( true ); + textArea_.setWrapStyleWord( true ); + + /* These cause the this-escape warning, but are perfectly safe in this + * context. */ + setPreferredSize( new Dimension( 300, 200 ) ); + getContentPane().add( textArea_ ); + addHelp( null ); + } + + /** + * Used to set the text to display in the Cell View window. + * + * @param text Text to display in this component. + */ + public void setText( String text ) { + textArea_.selectAll(); + textArea_.replaceSelection( text ); + } +} diff --git a/topcat/src/main/uk/ac/starlink/topcat/TableViewerWindow.java b/topcat/src/main/uk/ac/starlink/topcat/TableViewerWindow.java index bd39e93e7..ca1f8aa9c 100644 --- a/topcat/src/main/uk/ac/starlink/topcat/TableViewerWindow.java +++ b/topcat/src/main/uk/ac/starlink/topcat/TableViewerWindow.java @@ -563,6 +563,30 @@ public void actionPerformed( ActionEvent evt ) { popper.add( explodeAct ); } + popper.addSeparator(); + + /* Get the current row that is being selected. */ + final int jrow = rowSelectionModel_.getMinSelectionIndex(); + + /* Action to open the cell text in a viewer. */ + Action viewCellAct = + new BasicAction( "View Cell", ResourceIcon.ZOOM_IN, + "View the cell contents in a viewer." ) { + public void actionPerformed( ActionEvent evt ) { + CellViewWindow cell_view = + new CellViewWindow( "Cell Viewer", parent ); + TableModel tm = jtable_.getModel(); + String selectedCell = tm.getValueAt( jrow, jcol ).toString(); + cell_view.setText( selectedCell ); + cell_view.setVisible( true ); + } + }; + + /* Only enable the Cell View option if something is selected. If no row + * column is selected, it will be displayed in deactived state. */ + viewCellAct.setEnabled( jrow >= 0 && jcol >= 0 ); + popper.add( viewCellAct ); + return popper; }