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

Generalize options card #79

Open
wants to merge 5 commits into
base: viewer-mode-panel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions src/main/java/bdv/ui/BdvDefaultCards.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
package bdv.ui;

import bdv.ui.convertersetupeditor.ConverterSetupEditPanel;
import bdv.ui.iconcards.options.BdvIconOptions;
import bdv.ui.iconcards.options.DefaultIconOptionsCard;
import bdv.ui.sourcegrouptree.SourceGroupTree;
import bdv.ui.sourcetable.SourceTable;
import bdv.ui.viewermodepanel.ViewerModesPanel;
import bdv.viewer.ConverterSetups;
import bdv.viewer.SynchronizedViewerState;
import bdv.viewer.ViewerPanel;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.KeyboardFocusManager;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import org.scijava.ui.behaviour.util.TriggerBehaviourBindings;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.tree.TreeSelectionModel;
import org.scijava.ui.behaviour.util.TriggerBehaviourBindings;
import java.awt.*;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

/**
* Default cards added to the card panel.
Expand All @@ -38,7 +34,7 @@ public class BdvDefaultCards

public static final String DEFAULT_VIEWERMODES_CARD = "default bdv viewer modes card";

public static void setup( final CardPanel cards, final ViewerPanel viewer, final ConverterSetups converterSetups, final TriggerBehaviourBindings triggerbindings )
public static void addSourcesAndGroups(final CardPanel cards, final ViewerPanel viewer, final ConverterSetups converterSetups, final TriggerBehaviourBindings triggerbindings )
{
final SynchronizedViewerState state = viewer.state();

Expand Down Expand Up @@ -130,8 +126,14 @@ else if ( component == tablePanel )
}
} );

cards.addCard( DEFAULT_VIEWERMODES_CARD, "Viewer Modes", new ViewerModesPanel( viewer.state(), triggerbindings ), true, new Insets( 0, 4, 0, 0 ) );
cards.addCard( DEFAULT_SOURCES_CARD, "Sources", tablePanel, true, new Insets( 0, 4, 0, 0 ) );
cards.addCard( DEFAULT_SOURCEGROUPS_CARD, "Groups", treePanel, true, new Insets( 0, 4, 0, 0 ) );
}

public static void addOptions( CardPanel cards, ViewerPanel viewer, TriggerBehaviourBindings triggerbindings )
{
DefaultIconOptionsCard optionsCard = new DefaultIconOptionsCard();
BdvIconOptions.addToCard( viewer.state(), triggerbindings, optionsCard );
cards.addCard( DEFAULT_VIEWERMODES_CARD, "Options", optionsCard, true, new Insets( 0, 4, 0, 0 ) );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package bdv.ui.iconcards.options;

import java.awt.Font;
import java.util.List;
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import net.miginfocom.swing.MigLayout;

public class AnnotatedToggleGroupButton extends JPanel
{

private final ToggleGroupButton button;

private final JLabel annotation;

private final List< String> annotations;

public AnnotatedToggleGroupButton( final List< Icon > toggleIcons, final List< String > toggleLabels, final List< Runnable > toggleActions, final List< String > annotations )
{
this.annotations = annotations;

button = new ToggleGroupButton( toggleIcons, toggleLabels, toggleActions );
annotation = new JLabel( annotations.get( button.getCurrent() ) );

this.setLayout( new MigLayout( "ins 0, fillx, filly", "[]", "[]0lp![]" ) );

this.add( button, "growx, center, wrap" );
this.add( annotation, "center" );

button.addChangeListener( l -> {updateAnnotation();} );
}

private void updateAnnotation()
{
annotation.setText( annotations.get( button.getCurrent() ) );
// annotation.invalidate();
this.update( annotation.getGraphics() );
}

public void setAnnotationFont(final Font font)
{
annotation.setFont( font );
}

public synchronized void next() {
button.next();
}

public synchronized void setCurrent(final int index) {
button.setCurrent( index );
}

public synchronized void setCurrent(final String label) {
button.setCurrent( label );
}

public synchronized int getCurrent() { return button.getCurrent(); }

public synchronized int getIndexOfLabel(final String label) {
return button.getIndexOfLabel( label );
}

public synchronized void addOption( final Icon icon, final String label, final Runnable action, final String annotation) {
button.addOption( icon, label, action );
annotations.add(annotation);
}

public synchronized void removeOption(final String label) {
removeOption( button.getIndexOfLabel( label ) );
}

public synchronized void removeOption(final int index) {
button.removeOption( index );
annotations.remove( index );
}
}
152 changes: 152 additions & 0 deletions src/main/java/bdv/ui/iconcards/options/BdvIconOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
package bdv.ui.iconcards.options;

import bdv.ui.viewermodepanel.ViewerModesModel;
import bdv.viewer.Interpolation;
import bdv.viewer.SynchronizedViewerState;
import bdv.viewer.ViewerState;
import org.scijava.ui.behaviour.util.TriggerBehaviourBindings;

import java.net.URL;

/**
* @author Tim-Oliver Buchholz, CSBD/MPI-CBG, Dresden
* @author Deborah Schmidt, CSBD/MPI-CBG, Dresden
*/
public class BdvIconOptions implements ViewerModesModel.ViewerModeListener
{

private final ViewerModesModel viewerModesModel;

private final IconOptionsCard card;

public final static String OPTIONS_GROUP_DISPLAYMODES = "Display Modes";

public final static String OPTIONS_GROUP_NAVIGATION = "Navigation";

private static String OPTIONS_FUSION = "fusion";

private static String OPTIONS_FUSION_SINGLE = "Single";

private static String OPTIONS_FUSION_FUSED = "Fused";

private static String OPTIONS_GROUPING = "grouping";

private static String OPTIONS_GROUPING_GROUPED = "Group";

private static String OPTIONS_GROUPING_SOURCE = "Source";

private static String OPTIONS_INTERPOLATION = "interpolation";

private static String OPTIONS_INTERPOLATION_NEAREST = "Nearest";

private static String OPTIONS_INTERPOLATION_LINEAR = "Linear";

private static String OPTIONS_TRANSLATION = "translation";

private static String OPTIONS_TRANSLATION_ON = "translation on";

private static String OPTIONS_TRANSLATION_OFF = "translation off";

private static String OPTIONS_ROTATION = "rotation";

private static String OPTIONS_ROTATION_ON = "rotation on";

private static String OPTIONS_ROTATION_OFF = "rotation off";

public BdvIconOptions( final ViewerState state, final TriggerBehaviourBindings triggerBindings, final IconOptionsCard card )
{
viewerModesModel = new ViewerModesModel( state, triggerBindings );
viewerModesModel.addViewerModeListener( this );
this.card = card;
createFusionChoices();
createGroupingChoices();
createInterpolationChoices();
createTranslationChoices();
createRotationChoices();
}

public static void addToCard( SynchronizedViewerState state, TriggerBehaviourBindings triggerbindings, DefaultIconOptionsCard card )
{
new BdvIconOptions( state, triggerbindings, card );
}

private void createRotationChoices()
{
final URL rotation_on = this.getClass().getResource( "/bdv/ui/viewermodepanel/rotation_on.png" );
final URL rotation_off = this.getClass().getResource( "/bdv/ui/viewermodepanel/rotation_off.png" );
card.addOptionChoice( OPTIONS_GROUP_NAVIGATION, OPTIONS_ROTATION, OPTIONS_ROTATION_OFF, viewerModesModel::blockRotation, rotation_off );
card.addOptionChoice( OPTIONS_GROUP_NAVIGATION, OPTIONS_ROTATION, OPTIONS_ROTATION_ON, viewerModesModel::unblockRotation, rotation_on );
card.setSelected( OPTIONS_GROUP_NAVIGATION, OPTIONS_ROTATION, OPTIONS_ROTATION_ON );
}

private void createTranslationChoices()
{
final URL translation_on = this.getClass().getResource( "/bdv/ui/viewermodepanel/translation_on.png" );
final URL translation_off = this.getClass().getResource( "/bdv/ui/viewermodepanel/translation_off.png" );
card.addOptionChoice( OPTIONS_GROUP_NAVIGATION, OPTIONS_TRANSLATION, OPTIONS_TRANSLATION_OFF, viewerModesModel::blockTranslation, translation_off );
card.addOptionChoice( OPTIONS_GROUP_NAVIGATION, OPTIONS_TRANSLATION, OPTIONS_TRANSLATION_ON, viewerModesModel::unblockTranslation, translation_on );
card.setSelected( OPTIONS_GROUP_NAVIGATION, OPTIONS_TRANSLATION, OPTIONS_TRANSLATION_ON );
}

private void createInterpolationChoices()
{
final URL nearest_icon = this.getClass().getResource( "/bdv/ui/viewermodepanel/nearest.png" );
final URL linear_icon = this.getClass().getResource( "/bdv/ui/viewermodepanel/linear.png" );
Runnable linearAction = () -> viewerModesModel.setInterpolation( Interpolation.NLINEAR );
Runnable nearestAction = () -> viewerModesModel.setInterpolation( Interpolation.NEARESTNEIGHBOR );
card.addOptionChoice( OPTIONS_GROUP_DISPLAYMODES, OPTIONS_INTERPOLATION, OPTIONS_INTERPOLATION_LINEAR, linearAction, linear_icon );
card.addOptionChoice( OPTIONS_GROUP_DISPLAYMODES, OPTIONS_INTERPOLATION, OPTIONS_INTERPOLATION_NEAREST, nearestAction, nearest_icon );
interpolationMode( Interpolation.NLINEAR );
}

private void createGroupingChoices()
{
final URL grouping_icon = this.getClass().getResource( "/bdv/ui/viewermodepanel/grouping_mode.png" );
final URL source_icon = this.getClass().getResource( "/bdv/ui/viewermodepanel/source_mode.png" );
card.addOptionChoice( OPTIONS_GROUP_DISPLAYMODES, OPTIONS_GROUPING, OPTIONS_GROUPING_SOURCE, () -> viewerModesModel.setGrouping( false ), source_icon );
card.addOptionChoice( OPTIONS_GROUP_DISPLAYMODES, OPTIONS_GROUPING, OPTIONS_GROUPING_GROUPED, () -> viewerModesModel.setGrouping( true ), grouping_icon );
sourceMode();
}

private void createFusionChoices()
{
final URL fusion_icon = this.getClass().getResource( "/bdv/ui/viewermodepanel/fusion_mode.png" );
final URL single_icon = this.getClass().getResource( "/bdv/ui/viewermodepanel/single_mode.png" );
card.addOptionChoice( OPTIONS_GROUP_DISPLAYMODES, OPTIONS_FUSION, OPTIONS_FUSION_SINGLE, () -> viewerModesModel.setFused( false ), single_icon );
card.addOptionChoice( OPTIONS_GROUP_DISPLAYMODES, OPTIONS_FUSION, OPTIONS_FUSION_FUSED, () -> viewerModesModel.setFused( true ), fusion_icon );
singleMode();
}

@Override
public void fusedMode()
{
card.setSelected( OPTIONS_GROUP_DISPLAYMODES, OPTIONS_FUSION, OPTIONS_FUSION_FUSED );
}

@Override
public void singleMode()
{
card.setSelected( OPTIONS_GROUP_DISPLAYMODES, OPTIONS_FUSION, OPTIONS_FUSION_SINGLE );
}

@Override
public void sourceMode()
{
card.setSelected( OPTIONS_GROUP_DISPLAYMODES, OPTIONS_GROUPING, OPTIONS_GROUPING_SOURCE );
}

@Override
public void groupMode()
{
card.setSelected( OPTIONS_GROUP_DISPLAYMODES, OPTIONS_GROUPING, OPTIONS_GROUPING_GROUPED );
}

@Override
public void interpolationMode( Interpolation interpolation_mode )
{
if ( interpolation_mode.equals( Interpolation.NLINEAR ) )
card.setSelected( OPTIONS_GROUP_DISPLAYMODES, OPTIONS_INTERPOLATION, OPTIONS_INTERPOLATION_LINEAR );
if ( interpolation_mode.equals( Interpolation.NEARESTNEIGHBOR ) )
card.setSelected( OPTIONS_GROUP_DISPLAYMODES, OPTIONS_INTERPOLATION, OPTIONS_INTERPOLATION_NEAREST );
}
}
Loading