Skip to content

Commit

Permalink
Add Focus Column to jTable menu
Browse files Browse the repository at this point in the history
  • Loading branch information
tischi committed Jul 9, 2024
1 parent 3240b25 commit 7785a3f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<groupId>org.embl.mobie</groupId>
<artifactId>mobie-viewer-fiji</artifactId>
<version>5.1.7-SNAPSHOT</version>
<version>5.1.8</version>

<!-- mvn clean install -Dmaven.test.skip=true -Dscijava.app.directory=/Users/tischer/Desktop/Fiji/Fiji-MoBIE.app -->

Expand Down
32 changes: 32 additions & 0 deletions src/main/java/org/embl/mobie/lib/table/TableView.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import de.embl.cba.tables.Logger;
import de.embl.cba.tables.TableUIs;
import de.embl.cba.tables.Tables;
import ij.IJ;
import ij.gui.GenericDialog;
import org.embl.mobie.io.util.IOHelper;
Expand Down Expand Up @@ -198,6 +199,8 @@ private JMenuBar createMenuBar()

menuBar.add( createComputeMenu() );

menuBar.add( createMiscMenu() );

return menuBar;
}

Expand All @@ -211,6 +214,13 @@ private JMenu createSelectionMenu()
return menu;
}

private JMenu createMiscMenu()
{
JMenu menu = new JMenu( "Misc" );
menu.add( createColumnSearchMenuItem() );
return menu;
}

private JMenu createComputeMenu()
{
JMenu menu = new JMenu( "Analyse" );
Expand Down Expand Up @@ -355,6 +365,28 @@ private JMenuItem createSelectAllMenuItem()
return menuItem;
}

private JMenuItem createColumnSearchMenuItem()
{
final JMenuItem menuItem = new JMenuItem( "Focus Column..." );
menuItem.addActionListener( e ->
SwingUtilities.invokeLater( () ->
{
final String[] columnNames = Tables.getColumnNamesAsArray( jTable );
final GenericDialog gd = new GenericDialog( "Focus Column" );
gd.addChoice( "Column", columnNames, columnNames[ 0 ] );
gd.showDialog();
if ( gd.wasCanceled() ) return;
final String columnName = gd.getNextChoice();
int columnIndex = jTable.getColumnModel().getColumnIndex( columnName );
JViewport viewport = (JViewport) jTable.getParent();
Rectangle rect = jTable.getCellRect(0, columnIndex, true);
Point pt = viewport.getViewPosition();
rect.setLocation(rect.x - pt.x, rect.y - pt.y);
viewport.scrollRectToVisible(rect);
}) );
return menuItem;
}

private JMenuItem createComputeDistanceMenuItem()
{
final JMenuItem menuItem = new JMenuItem( "Compute Distance to Selected Rows..." );
Expand Down

0 comments on commit 7785a3f

Please sign in to comment.