Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shuffling menu items inside the Plugins submenu #6

Merged
merged 10 commits into from
Jul 19, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public DatasetPathDialog( final Frame owner, final MamutProject project )
c.gridy = 0;
c.gridx = 0;
c.weightx = 0.0;
content.add( new JLabel( "BDV dataset path" ), c );
content.add( new JLabel( "Current BDV dataset path: " ), c );

final JTextField pathTextField = new JTextField( project.getDatasetXmlFile().getAbsolutePath() );
c.gridx = 1;
Expand All @@ -94,7 +94,7 @@ public DatasetPathDialog( final Frame owner, final MamutProject project )

++c.gridy;
c.gridx = 0;
content.add( new JLabel( "store absolute path" ), c );
content.add( new JLabel( "Store as absolute path: " ), c );
final JCheckBox storeAbsoluteCheckBox = new JCheckBox();
storeAbsoluteCheckBox.setSelected( !project.isDatasetXmlPathRelative() );
c.gridx = 1;
Expand Down
132 changes: 90 additions & 42 deletions src/main/java/org/mastodon/mamut/tomancak/TomancakPlugins.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@
import org.mastodon.mamut.plugin.MamutPluginAppModel;
import org.mastodon.mamut.project.MamutProject;
import org.mastodon.mamut.tomancak.compact_lineage.CompactLineageFrame;
import org.mastodon.mamut.tomancak.export.MakePhyloXml;
import org.mastodon.mamut.tomancak.merging.Dataset;
import org.mastodon.mamut.tomancak.merging.MergeDatasets;
import org.mastodon.mamut.tomancak.merging.MergingDialog;
import org.mastodon.mamut.tomancak.sort_tree.FlipDescendants;
import org.mastodon.mamut.tomancak.sort_tree.SortTreeDialog;
import org.mastodon.mamut.tomancak.spots.InterpolateMissingSpots;
import org.mastodon.model.SelectionModel;
import org.mastodon.ui.keymap.CommandDescriptionProvider;
import org.mastodon.ui.keymap.CommandDescriptions;
Expand All @@ -63,36 +69,39 @@
@Plugin( type = MamutPlugin.class )
public class TomancakPlugins extends AbstractContextual implements MamutPlugin
{
private static final String EXPORT_PHYLOXML = "[tomancak] export phyloxml for selection";
private static final String FLIP_DESCENDANTS = "[tomancak] flip descendants";
private static final String COPY_TAG = "[tomancak] copy tag";
private static final String INTERPOLATE_SPOTS = "[tomancak] interpolate spots";
private static final String TWEAK_DATASET_PATH = "[tomancak] tweak dataset path";
private static final String LABEL_SELECTED_SPOTS = "[tomancak] label spots";
private static final String COMPACT_LINEAGE_VIEW = "[tomancak] lineage tree view";
private static final String SORT_TREE = "[tomancak] sort tree";
private static final String EXPORT_PHYLOXML = "[exports] export phyloxml for selection";
private static final String FLIP_DESCENDANTS = "[trees] flip descendants";
private static final String COPY_TAG = "copy tag";
private static final String INTERPOLATE_SPOTS = "[trees] interpolate missing spots";
private static final String LABEL_SELECTED_SPOTS = "[trees] label selected spots";
private static final String COMPACT_LINEAGE_VIEW = "[displays] show compact lineage";
private static final String SORT_TREE = "[trees] sort lineage tree";
private static final String MERGE_PROJECTS = "merge projects";
private static final String TWEAK_DATASET_PATH = "fix project image path";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no strong opinion here, but maybe let's keep the "[tomancak] ..." prefix here. It's more consistent, and gives an indication in the settings dialog that this plugin belongs to mastodon-tomancak.

Copy link
Collaborator Author

@xulman xulman Jul 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, changed that back to [tomancak]... I also don't have a strong opinion on that

the original idea was to be able to group/filter related activities with a single keyword.. and so was essentially mirroring the menu layout in the brackets (besides, now that this repo is among the default installed, user is probably not realizing/not cares (maybe?)/does not see the source of this functionality)

but words like lineage, spot, sort... tend to group reasonably well and a user can see everything relevant and adjust/overview shortcuts in the key bindings dialog... so my primary goal is preserved and thus I'm happy :-)

I've took care of it in the commit dde59b7


private static final String[] EXPORT_PHYLOXML_KEYS = { "not mapped" };
private static final String[] FLIP_DESCENDANTS_KEYS = { "not mapped" };
private static final String[] COPY_TAG_KEYS = { "not mapped" };
private static final String[] INTERPOLATE_SPOTS_KEYS = { "not mapped" };
private static final String[] TWEAK_DATASET_PATH_KEYS = { "not mapped" };
private static final String[] LABEL_SELECTED_SPOTS_KEYS = { "not mapped" };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

F2 would be nice as a key combination for renaming spots.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very cool idea... -> commit 7d2b553

private static final String[] COMPACT_LINEAGE_VIEW_KEYS = { "not mapped" };
private static final String[] SORT_TREE_KEYS = { "not mapped" };
private static final String[] MERGE_PROJECTS_KEYS = { "not mapped" };
private static final String[] TWEAK_DATASET_PATH_KEYS = { "not mapped" };

private static Map< String, String > menuTexts = new HashMap<>();

static
{
menuTexts.put( EXPORT_PHYLOXML, "Export phyloXML for selection" );
menuTexts.put( FLIP_DESCENDANTS, "Flip descendants" );
menuTexts.put( COPY_TAG, "Copy Tag..." );
menuTexts.put( INTERPOLATE_SPOTS, "Interpolate missing spots" );
menuTexts.put( TWEAK_DATASET_PATH, "Edit BDV XML path..." );
menuTexts.put( LABEL_SELECTED_SPOTS, "Label selected spots..." );
menuTexts.put( COMPACT_LINEAGE_VIEW, "Show compact lineage" );
menuTexts.put( SORT_TREE, "Sort lineage tree..." );
menuTexts.put( EXPORT_PHYLOXML, "Export phyloXML for Selection" );
menuTexts.put( FLIP_DESCENDANTS, "Flip Descendants" );
menuTexts.put( COPY_TAG, "Copy Tag" );
menuTexts.put( INTERPOLATE_SPOTS, "Interpolate Missing Spots" );
menuTexts.put( LABEL_SELECTED_SPOTS, "Label Selected Spots" );
menuTexts.put( COMPACT_LINEAGE_VIEW, "Show Compact Lineage" );
menuTexts.put( SORT_TREE, "Sort Lineage Tree" );
menuTexts.put( MERGE_PROJECTS, "Merge Two Projects" );
menuTexts.put( TWEAK_DATASET_PATH, "Fix Image Path" );
}

/*
Expand All @@ -110,13 +119,14 @@ public Descriptions()
public void getCommandDescriptions( final CommandDescriptions descriptions )
{
descriptions.add( EXPORT_PHYLOXML, EXPORT_PHYLOXML_KEYS, "Export subtree to PhyloXML format." );
descriptions.add( FLIP_DESCENDANTS, FLIP_DESCENDANTS_KEYS, "Flip children in trackscheme graph." );
descriptions.add( FLIP_DESCENDANTS, FLIP_DESCENDANTS_KEYS, "Flip children of the currently selected spot in trackscheme graph." );
descriptions.add( COPY_TAG, COPY_TAG_KEYS, "Copy tags: everything that has tag A assigned gets B assigned." );
descriptions.add( INTERPOLATE_SPOTS, INTERPOLATE_SPOTS_KEYS, "Interpolate missing spots." );
descriptions.add( TWEAK_DATASET_PATH, TWEAK_DATASET_PATH_KEYS, "Set the path to the BDV data and whether it is relative or absolute." );
descriptions.add( INTERPOLATE_SPOTS, INTERPOLATE_SPOTS_KEYS, "Along each track, new spot is inserted to every time points with no spots." );
descriptions.add( LABEL_SELECTED_SPOTS, LABEL_SELECTED_SPOTS_KEYS, "Set label for all selected spots." );
descriptions.add( COMPACT_LINEAGE_VIEW, COMPACT_LINEAGE_VIEW_KEYS, "Show compact representation of the lineage tree.");
descriptions.add( SORT_TREE, SORT_TREE_KEYS, "Sort selected node according to tagged anchors.");
descriptions.add( MERGE_PROJECTS, MERGE_PROJECTS_KEYS, "Merge two Mastodon projects into one." );
descriptions.add( TWEAK_DATASET_PATH, TWEAK_DATASET_PATH_KEYS, "Allows to insert new path to the BDV data and whether it is relative or absolute." );
}
}

Expand All @@ -128,14 +138,16 @@ public void getCommandDescriptions( final CommandDescriptions descriptions )

private final AbstractNamedAction interpolateSpotsAction;

private final AbstractNamedAction tweakDatasetPathAction;

private final AbstractNamedAction labelSelectedSpotsAction;

private final AbstractNamedAction lineageTreeViewAction;

private final AbstractNamedAction sortTreeAction;

private final AbstractNamedAction mergeProjectsAction;

private final AbstractNamedAction tweakDatasetPathAction;

private MamutPluginAppModel pluginAppModel;

public TomancakPlugins()
Expand All @@ -144,10 +156,11 @@ public TomancakPlugins()
flipDescendantsAction = new RunnableAction( FLIP_DESCENDANTS, this::flipDescendants );
copyTagAction = new RunnableAction( COPY_TAG, this::copyTag );
interpolateSpotsAction = new RunnableAction( INTERPOLATE_SPOTS, this::interpolateSpots );
tweakDatasetPathAction = new RunnableAction( TWEAK_DATASET_PATH, this::tweakDatasetPath );
labelSelectedSpotsAction = new RunnableAction( LABEL_SELECTED_SPOTS, this::labelSelectedSpots );
lineageTreeViewAction = new RunnableAction( COMPACT_LINEAGE_VIEW, this::showLineageView );
sortTreeAction = new RunnableAction( SORT_TREE, this::sortTree );
mergeProjectsAction = new RunnableAction( MERGE_PROJECTS, this::mergeProjects );
tweakDatasetPathAction = new RunnableAction( TWEAK_DATASET_PATH, this::tweakDatasetPath );
updateEnabledActions();
}

Expand All @@ -163,15 +176,19 @@ public List< ViewMenuBuilder.MenuItem > getMenuItems()
{
return Arrays.asList(
menu( "Plugins",
menu( "Tomancak lab",
item( EXPORT_PHYLOXML ),
item( FLIP_DESCENDANTS ),
item( INTERPOLATE_SPOTS ),
item( COPY_TAG ),
menu( "Auxiliary Displays",
item( COMPACT_LINEAGE_VIEW )),
menu( "Trees Management",
item( LABEL_SELECTED_SPOTS ),
item( COPY_TAG ),
item( TWEAK_DATASET_PATH ),
item( COMPACT_LINEAGE_VIEW ),
item( SORT_TREE )) ) );
item( INTERPOLATE_SPOTS ),
item( FLIP_DESCENDANTS ),
item( SORT_TREE )),
menu( "Exports",
item( EXPORT_PHYLOXML )) ),
menu( "File",
item( TWEAK_DATASET_PATH ),
item( MERGE_PROJECTS )) );
}

@Override
Expand All @@ -187,10 +204,11 @@ public void installGlobalActions( final Actions actions )
actions.namedAction( flipDescendantsAction, FLIP_DESCENDANTS_KEYS );
actions.namedAction( copyTagAction, COPY_TAG_KEYS );
actions.namedAction( interpolateSpotsAction, INTERPOLATE_SPOTS_KEYS );
actions.namedAction( tweakDatasetPathAction, TWEAK_DATASET_PATH_KEYS );
actions.namedAction( labelSelectedSpotsAction, LABEL_SELECTED_SPOTS_KEYS );
actions.namedAction( lineageTreeViewAction, COMPACT_LINEAGE_VIEW_KEYS );
actions.namedAction( sortTreeAction, SORT_TREE_KEYS );
actions.namedAction( mergeProjectsAction, MERGE_PROJECTS_KEYS );
actions.namedAction( tweakDatasetPathAction, TWEAK_DATASET_PATH_KEYS );
}

private void updateEnabledActions()
Expand All @@ -200,10 +218,11 @@ private void updateEnabledActions()
flipDescendantsAction.setEnabled( appModel != null );
copyTagAction.setEnabled( appModel != null );
interpolateSpotsAction.setEnabled( appModel != null );
tweakDatasetPathAction.setEnabled( appModel != null );
labelSelectedSpotsAction.setEnabled( appModel != null );
lineageTreeViewAction.setEnabled( appModel != null );
sortTreeAction.setEnabled( appModel != null );
mergeProjectsAction.setEnabled( appModel != null );
tweakDatasetPathAction.setEnabled( appModel != null );
}

private void exportPhyloXml()
Expand Down Expand Up @@ -236,15 +255,6 @@ private void interpolateSpots()
}
}

private void tweakDatasetPath()
{
if ( pluginAppModel != null )
{
final MamutProject project = pluginAppModel.getWindowManager().getProjectManager().getProject();
new DatasetPathDialog( null, project ).setVisible( true );
}
}

private void labelSelectedSpots()
{
if ( pluginAppModel != null )
Expand Down Expand Up @@ -292,4 +302,42 @@ private void showLineageView() {
frame.setVisible(true);
}

private MergingDialog mergingDialog;

private void mergeProjects()
{
if ( mergingDialog == null )
mergingDialog = new MergingDialog( null );
mergingDialog.onMerge( () ->
{
try
{
final String pathA = mergingDialog.getPathA();
final String pathB = mergingDialog.getPathB();
final double distCutoff = mergingDialog.getDistCutoff();
final double mahalanobisDistCutoff = mergingDialog.getMahalanobisDistCutoff();
final double ratioThreshold = mergingDialog.getRatioThreshold();

final Dataset dsA = new Dataset( pathA );
final Dataset dsB = new Dataset( pathB );
pluginAppModel.getWindowManager().getProjectManager().open( new MamutProject( null, dsA.project().getDatasetXmlFile() ) );
final MergeDatasets.OutputDataSet output = new MergeDatasets.OutputDataSet( pluginAppModel.getAppModel().getModel() );
MergeDatasets.merge( dsA, dsB, output, distCutoff, mahalanobisDistCutoff, ratioThreshold );
}
catch( final Exception e )
{
e.printStackTrace();
}
} );
mergingDialog.setVisible( true );
}

private void tweakDatasetPath()
{
if ( pluginAppModel != null )
{
final MamutProject project = pluginAppModel.getWindowManager().getProjectManager().getProject();
new DatasetPathDialog( null, project ).setVisible( true );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/
package org.mastodon.mamut.tomancak;
package org.mastodon.mamut.tomancak.export;

import java.io.File;
import java.io.FileOutputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.mastodon.mamut.model.Model;
import org.mastodon.mamut.model.ModelGraph;
import org.mastodon.mamut.model.Spot;
import org.mastodon.mamut.tomancak.InterpolateMissingSpots;
import org.mastodon.mamut.tomancak.spots.InterpolateMissingSpots;
import org.mastodon.mamut.tomancak.merging.MergeDatasets.OutputDataSet;
import org.mastodon.mamut.tomancak.merging.MergeTags.TagSetStructureMaps;
import org.mastodon.model.tag.ObjTags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public MergingDialog( final Frame owner )

c.gridy = 0;
c.gridx = 0;
content.add( new JLabel( "Project A" ), c );
content.add( new JLabel( "Project A: " ), c );
pathATextField = new JTextField( "" );
c.gridx = 1;
c.anchor = GridBagConstraints.LINE_START;
Expand All @@ -103,7 +103,7 @@ public MergingDialog( final Frame owner )

++c.gridy;
c.gridx = 0;
content.add( new JLabel( "Project B" ), c );
content.add( new JLabel( "Project B: " ), c );
pathBTextField = new JTextField( "" );
c.gridx = 1;
content.add( pathBTextField, c );
Expand All @@ -114,21 +114,21 @@ public MergingDialog( final Frame owner )

++c.gridy;
c.gridx = 0;
content.add( new JLabel( "absolute distance cutoff" ), c );
content.add( new JLabel( "Absolute distance cutoff: " ), c );
distCutoffTextField = new JTextField( "1000" );
c.gridx = 1;
content.add( distCutoffTextField, c );

++c.gridy;
c.gridx = 0;
content.add( new JLabel( "mahalanobis distance cutoff" ), c );
content.add( new JLabel( "Mahalanobis distance cutoff: " ), c );
mahalanobisDistCutoffTextField = new JTextField( "1" );
c.gridx = 1;
content.add( mahalanobisDistCutoffTextField, c );

++c.gridy;
c.gridx = 0;
content.add( new JLabel( "ratio threshold" ), c );
content.add( new JLabel( "Ratio threshold: " ), c );
ratioThresholdTextField = new JTextField( "2" );
c.gridx = 1;
content.add( ratioThresholdTextField, c );
Expand Down
Loading