diff --git a/src/main/java/bdv/ui/BdvDefaultCards.java b/src/main/java/bdv/ui/BdvDefaultCards.java index ff64041c5..e39eb88fd 100644 --- a/src/main/java/bdv/ui/BdvDefaultCards.java +++ b/src/main/java/bdv/ui/BdvDefaultCards.java @@ -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. @@ -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(); @@ -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 ) ); + } } diff --git a/src/main/java/bdv/ui/iconcards/options/AnnotatedToggleGroupButton.java b/src/main/java/bdv/ui/iconcards/options/AnnotatedToggleGroupButton.java new file mode 100644 index 000000000..b9b044281 --- /dev/null +++ b/src/main/java/bdv/ui/iconcards/options/AnnotatedToggleGroupButton.java @@ -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 ); + } +} diff --git a/src/main/java/bdv/ui/iconcards/options/BdvIconOptions.java b/src/main/java/bdv/ui/iconcards/options/BdvIconOptions.java new file mode 100644 index 000000000..12330ce8c --- /dev/null +++ b/src/main/java/bdv/ui/iconcards/options/BdvIconOptions.java @@ -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 ); + } +} diff --git a/src/main/java/bdv/ui/iconcards/options/DefaultIconOptionsCard.java b/src/main/java/bdv/ui/iconcards/options/DefaultIconOptionsCard.java new file mode 100644 index 000000000..4a6683f32 --- /dev/null +++ b/src/main/java/bdv/ui/iconcards/options/DefaultIconOptionsCard.java @@ -0,0 +1,148 @@ +package bdv.ui.iconcards.options; + +import net.miginfocom.swing.MigLayout; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +/** + * @author Deborah Schmidt, CSBD/MPI-CBG, Dresden + */ +public class DefaultIconOptionsCard extends JPanel implements IconOptionsCard +{ + + int iconSize = 40; + + class OptionGroup + { + JPanel panel; + + final Map options = new HashMap<>(); + } + + class Option + { + final Map choices = new HashMap<>(); + + public JPopupMenu menu; + + JButton button; + } + + private final Map groups = new HashMap<>(); + + public DefaultIconOptionsCard() + { + setLayout( new MigLayout( "fillx, nogrid, ins n 0 n 0, gap 0" ) ); + setBackground( null ); + setOpaque( false ); + setForeground( Color.lightGray ); + } + + public void addGroup( String optionGroup ) + { + final JPanel panel = new JPanel( new MigLayout( "ins 0, fillx, filly", "", "top" ) ); + panel.setBackground( null ); + panel.setOpaque( false ); + panel.add( new JLabel( optionGroup ), "span 3, growx, center, wrap" ); + OptionGroup optionSet = new OptionGroup(); + optionSet.panel = panel; + groups.put( optionGroup, optionSet ); + add( panel ); + } + + @Override + public void removeGroup( String optionGroup ) + { + remove( groups.get( optionGroup ).panel ); + groups.remove( optionGroup ); + } + + @Override + public void addOptionChoice( String optionGroupName, String optionName, String choiceName, Runnable action, URL iconURL ) + { + if ( !groups.containsKey( optionGroupName ) ) + addGroup( optionGroupName ); + OptionGroup optionGroup = groups.get( optionGroupName ); + Option option = optionGroup.options.get( optionName ); + if ( option == null ) + option = addOption( optionName, optionGroup ); + ImageIcon icon = new ImageIcon( iconURL ); + option.choices.put( choiceName, icon ); + JMenuItem menuItem = new JMenuItem( new AbstractAction( choiceName ) + { + @Override + public void actionPerformed( ActionEvent actionEvent ) + { + action.run(); + } + } ); + Image newimg = icon.getImage().getScaledInstance( 20, 20, java.awt.Image.SCALE_SMOOTH ); + ImageIcon scaledIcon = new ImageIcon( newimg ); + menuItem.setIcon( scaledIcon ); + option.menu.add( menuItem ); + Option finalOption = option; + menuItem.addActionListener( actionEvent -> { + finalOption.button.setIcon( icon ); + finalOption.button.setToolTipText( createToolTipText( finalOption.choices, choiceName ) ); + } ); + } + + private Option addOption( String optionName, OptionGroup optionGroup ) + { + Option option; + option = new Option(); + optionGroup.options.put( optionName, option ); + JButton btn = new JButton(); + option.button = btn; + JPopupMenu menu = new JPopupMenu( optionName ); + option.menu = menu; + btn.addMouseListener( new MouseAdapter() + { + @Override + public void mouseClicked( MouseEvent mouseEvent ) + { + menu.show( btn, mouseEvent.getX(), mouseEvent.getY() ); + } + } ); + setLook( btn ); + optionGroup.panel.add( btn ); + return option; + } + + @Override + public void setSelected( String optionGroup, String optionName, String choiceName ) + { + Option option = groups.get( optionGroup ).options.get( optionName ); + ImageIcon choice = option.choices.get( choiceName ); + option.button.setIcon( choice ); + option.button.setToolTipText( createToolTipText( option.choices, choiceName ) ); + } + + private String createToolTipText( Map optionChoices, String currentChoice ) + { + return currentChoice; + } + + private void setLook( final JButton button ) + { + button.setMaximumSize( new Dimension( iconSize, iconSize ) ); + button.setBackground( Color.white ); + button.setBorderPainted( false ); + // button.setFocusPainted( false ); + // button.setContentAreaFilled( false ); + } + + @Override + public void removeOption( String optionGroup, String optionName ) + { + + } +} + diff --git a/src/main/java/bdv/ui/iconcards/options/IconOptionsCard.java b/src/main/java/bdv/ui/iconcards/options/IconOptionsCard.java new file mode 100644 index 000000000..a68d23fcd --- /dev/null +++ b/src/main/java/bdv/ui/iconcards/options/IconOptionsCard.java @@ -0,0 +1,22 @@ +package bdv.ui.iconcards.options; + +import java.net.URL; + +/** + * A card storing options in groups. + * Each option can have multiple choices, each choice linked to an action. + * + * @author Deborah Schmidt, CSBD/MPI-CBG, Dresden + */ +public interface IconOptionsCard +{ + + void addOptionChoice( String optionGroup, String optionName, String choiceName, Runnable action, URL iconURL ); + + void setSelected( String optionGroup, String optionName, String choiceName ); + + void removeOption( String optionGroup, String optionName ); + + void removeGroup( String optionGroup ); + +} diff --git a/src/main/java/bdv/ui/iconcards/options/ToggleGroupButton.java b/src/main/java/bdv/ui/iconcards/options/ToggleGroupButton.java new file mode 100644 index 000000000..926151465 --- /dev/null +++ b/src/main/java/bdv/ui/iconcards/options/ToggleGroupButton.java @@ -0,0 +1,187 @@ +package bdv.ui.iconcards.options; + +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.List; +import javax.swing.Icon; +import javax.swing.JButton; +import javax.swing.JMenuItem; +import javax.swing.JPopupMenu; +import javax.swing.SwingUtilities; + +/** + * A ToggleGroupButton holds a group of states, through which the user can toggle by left-clicking the button. + * If the user right-clicks on the button a popup menu will appear and the user can select one of the options + * directly. + * + * @author Tim-Oliver Buchholz, MPI-CBG, CSBD, Dresden, Germany + * @author Deborah Schmidt, MPI-CBG, CSBD, Dresden, Germany + */ +public class ToggleGroupButton extends JButton +{ + private final List< Icon > toggleIcons; + + private final List< Runnable > toggleActions; + + private final JPopupMenu menu; + + private final List< String > toggleLabels; + + private int current = 0; + + /** + * Create a new ToggleGroupButton. + * + * @param toggleIcons displayed on the button and in the popup menu + * @param toggleLabels displayed in the popup menu and tooltip + * @param toggleActions executed if the button switches to this action + */ + public ToggleGroupButton( final List< Icon > toggleIcons, final List< String > toggleLabels, final List< Runnable > toggleActions ) + { + this.toggleIcons = toggleIcons; + this.toggleLabels = toggleLabels; + this.toggleActions = toggleActions; + this.menu = new JPopupMenu(); + populatePopupMenu(); + + this.setContentAreaFilled( false ); + this.setFocusPainted( false ); + this.setBorderPainted( false ); + + this.setIcon( toggleIcons.get( current ) ); + this.setToolTipText( toggleLabels.get( current ) ); + addActionListener( a -> { + next(); + } ); + } + + private void populatePopupMenu() + { + menu.setInvoker( this ); + + for ( int i = 0; i < toggleActions.size(); i++ ) + { + createMenuItem( i ); + } + + this.addMouseListener( new MouseAdapter() + { + @Override + public void mouseClicked( MouseEvent mouseEvent ) + { + if ( SwingUtilities.isRightMouseButton( mouseEvent ) ) + menu.show( menu.getInvoker(), mouseEvent.getX(), mouseEvent.getY() ); + } + } ); + } + + private void createMenuItem( final int i ) + { + final JMenuItem item = new JMenuItem( toggleLabels.get( i ), toggleIcons.get( i ) ); + final int index = i; + item.addActionListener( a -> { + current = index; + trigger(); + } ); + menu.add( item ); + } + + /** + * Toggle to the next action in the list. + */ + public synchronized void next() + { + current = ( current + 1 ) % toggleActions.size(); + trigger(); + } + + /** + * Select a specific option. + * + * @param index modulo number-of-options is set. + */ + public synchronized void setCurrent( final int index ) + { + this.current = index % toggleActions.size(); + trigger(); + } + + /** + * Select an option via name. + * + * @param label of the option + */ + public synchronized void setCurrent( final String label ) + { + if ( toggleLabels.contains( label ) ) + { + current = toggleLabels.indexOf( label ); + trigger(); + } + } + + /** + * Get current selected option index. + * + * @return current index + */ + public synchronized int getCurrent() + { + return current; + } + + public synchronized int getIndexOfLabel(final String label) { + return toggleLabels.indexOf( label ); + } + + /** + * Add a new option. + * + * @param icon of the option + * @param label of the option + * @param action triggered by this option + */ + public synchronized void addOption( final Icon icon, final String label, final Runnable action ) + { + toggleIcons.add( icon ); + toggleLabels.add( label ); + toggleActions.add( action ); + createMenuItem( toggleIcons.size() - 1 ); + } + + /** + * Removes the option. + * + * @param label of the option + */ + public synchronized void removeOption( final String label ) + { + if ( toggleLabels.contains( label ) ) + { + removeOption( toggleLabels.indexOf( label ) ); + } + } + + /** + * Remove option via index. + * + * @param index + */ + public synchronized void removeOption( final int index ) + { + if ( index < toggleLabels.size() ) + { + toggleIcons.remove( index ); + toggleLabels.remove( index ); + toggleActions.remove( index ); + menu.remove( index ); + } + } + + private void trigger() + { + this.setIcon( toggleIcons.get( current ) ); + this.setToolTipText( toggleLabels.get( current ) ); + SwingUtilities.invokeLater( toggleActions.get( current ) ); + } +} diff --git a/src/main/java/bdv/ui/viewermodepanel/ViewerModesModel.java b/src/main/java/bdv/ui/viewermodepanel/ViewerModesModel.java index 7a062c3c7..9bb8e4d16 100644 --- a/src/main/java/bdv/ui/viewermodepanel/ViewerModesModel.java +++ b/src/main/java/bdv/ui/viewermodepanel/ViewerModesModel.java @@ -4,8 +4,10 @@ import bdv.viewer.Interpolation; import bdv.viewer.ViewerState; import bdv.viewer.ViewerStateChange; + import java.util.ArrayList; import java.util.List; + import org.scijava.ui.behaviour.Behaviour; import org.scijava.ui.behaviour.BehaviourMap; import org.scijava.ui.behaviour.util.TriggerBehaviourBindings; @@ -30,7 +32,7 @@ public class ViewerModesModel private BehaviourMap blockTranslationBehaviourMap; - private final List< ViewerModeListener > viewerModeListeners = new ArrayList<>(); + private final List viewerModeListeners = new ArrayList<>(); /** * Keeps track of the current viewer state and handles the transformation blocking. @@ -45,7 +47,8 @@ public ViewerModesModel( final ViewerState state, final TriggerBehaviourBindings if ( e == ViewerStateChange.DISPLAY_MODE_CHANGED ) { changeDisplayMode(); - } else if ( e == ViewerStateChange.INTERPOLATION_CHANGED ) + } + else if ( e == ViewerStateChange.INTERPOLATION_CHANGED ) { fireInterpolationMode( state.getInterpolation() ); } @@ -272,7 +275,7 @@ public void setInterpolation( final Interpolation interpolation_mode ) state.setInterpolation( interpolation_mode ); } - interface ViewerModeListener + public interface ViewerModeListener { void fusedMode(); diff --git a/src/main/java/bdv/ui/viewermodepanel/ViewerModesPanel.java b/src/main/java/bdv/ui/viewermodepanel/ViewerModesPanel.java deleted file mode 100644 index 471be26c9..000000000 --- a/src/main/java/bdv/ui/viewermodepanel/ViewerModesPanel.java +++ /dev/null @@ -1,256 +0,0 @@ -package bdv.ui.viewermodepanel; - -import bdv.viewer.Interpolation; -import bdv.viewer.ViewerState; -import java.awt.Color; -import java.awt.Dimension; -import javax.swing.Icon; -import javax.swing.ImageIcon; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JToggleButton; -import net.miginfocom.swing.MigLayout; -import org.scijava.ui.behaviour.util.TriggerBehaviourBindings; - -/** - * This panel adds buttons to toggle fused- and grouped-mode. - * Additionally two button to block translation and rotation are - * added. - * - * @author Tim-Oliver Buchholz, CSBD/MPI-CBG, Dresden - */ -public class ViewerModesPanel extends JPanel implements ViewerModesModel.ViewerModeListener -{ - - private static final String SINGLE_MODE_TOOL_TIP = "Single/Fused"; - - private static final String FUSED_MODE_TOOL_TIP = "Single/Fused"; - - private static final String GROUP_MODE_TOOL_TIP = "Source/Group"; - - private static final String SOURCE_MODE_TOOL_TIP = "Source/Group"; - - private static final String NEAREST_INTERPOLATION_TOOL_TIP = "Nearest/Linear"; - - private static final String LINEAR_INTERPOLATION_TOOL_TIP = "Nearest/Linear"; - - private static final String TRANSLATION_ACTIVE_TOOL_TIP = "Translation"; - - private static final String TRANSLATION_INACTIVE_TOOL_TIP = "Translation"; - - private static final String ROTATION_ACTIVE_TOOL_TIP = "Rotation"; - - private static final String ROTATION_INACTIVE_TOOL_TIP = "Rotation { - if ( fusion.getModel().isSelected() ) - { - fusion.setIcon( fusion_icon ); - fusion.setToolTipText( FUSED_MODE_TOOL_TIP ); - } - else - { - fusion.setIcon( single_icon ); - fusion.setToolTipText( SINGLE_MODE_TOOL_TIP ); - } - } ); - fusion.addActionListener( e -> { - viewerModesModel.setFused( fusion.getModel().isSelected() ); - } ); - } - - private void setupGroupedModeButton() - { - final Icon grouping_icon = new ImageIcon( this.getClass().getResource( "grouping_mode.png" ) ); - final Icon source_icon = new ImageIcon( this.getClass().getResource( "source_mode.png" ) ); - - grouping.setIcon( source_icon ); - grouping.setToolTipText( SOURCE_MODE_TOOL_TIP ); - setLook( grouping ); - grouping.getModel().addChangeListener( e -> { - if ( grouping.getModel().isSelected() ) - { - grouping.setIcon( grouping_icon ); - grouping.setToolTipText( GROUP_MODE_TOOL_TIP ); - } - else - { - grouping.setIcon( source_icon ); - grouping.setToolTipText( SOURCE_MODE_TOOL_TIP ); - } - } ); - grouping.addActionListener( e -> { - viewerModesModel.setGrouping( grouping.getModel().isSelected() ); - } ); - } - - private void setupInterpolationModeButton() - { - final Icon nearest_icon = new ImageIcon( this.getClass().getResource( "nearest.png" ) ); - final Icon linear_icon = new ImageIcon( this.getClass().getResource( "linear.png" ) ); - - interpolation.setIcon( nearest_icon ); - interpolation.setToolTipText( NEAREST_INTERPOLATION_TOOL_TIP ); - setLook( interpolation ); - interpolation.getModel().addChangeListener( e -> { - if ( interpolation.getModel().isSelected() ) - { - interpolation.setIcon( linear_icon ); - interpolation.setToolTipText( LINEAR_INTERPOLATION_TOOL_TIP ); - viewerModesModel.setInterpolation( Interpolation.NLINEAR ); - } else - { - interpolation.setIcon( nearest_icon ); - interpolation.setToolTipText( NEAREST_INTERPOLATION_TOOL_TIP ); - viewerModesModel.setInterpolation( Interpolation.NEARESTNEIGHBOR ); - } - } ); - } - - private void setupTranslationBlockButton() - { - final Icon translation_on = new ImageIcon( this.getClass().getResource( "translation_on.png" ) ); - final Icon translation_off = new ImageIcon( this.getClass().getResource( "translation_off.png" ) ); - - translation.setIcon( translation_on ); - translation.setToolTipText( TRANSLATION_ACTIVE_TOOL_TIP ); - setLook( translation ); - translation.addActionListener( e -> { - if ( translation.getModel().isSelected() ) - { - translation.setIcon( translation_off ); - translation.setToolTipText( TRANSLATION_INACTIVE_TOOL_TIP ); - viewerModesModel.blockTranslation(); - } - else - { - translation.setIcon( translation_on ); - translation.setToolTipText( TRANSLATION_ACTIVE_TOOL_TIP ); - viewerModesModel.unblockTranslation(); - } - } ); - } - - private void setupRotationBlockButton() - { - final Icon rotation_on = new ImageIcon( this.getClass().getResource( "rotation_on.png" ) ); - final Icon rotation_off = new ImageIcon( this.getClass().getResource( "rotation_off.png" ) ); - - rotation.setIcon( rotation_on ); - rotation.setToolTipText( ROTATION_ACTIVE_TOOL_TIP ); - setLook( rotation ); - rotation.addActionListener( e -> { - if ( rotation.getModel().isSelected() ) - { - rotation.setIcon( rotation_off ); - rotation.setToolTipText( ROTATION_INACTIVE_TOOL_TIP ); - viewerModesModel.blockRotation(); - } - else - { - rotation.setIcon( rotation_on ); - rotation.setToolTipText( ROTATION_ACTIVE_TOOL_TIP ); - viewerModesModel.unblockRotation(); - } - } ); - } - - private void setLook( final JToggleButton button ) - { - button.setMaximumSize( new Dimension( button.getIcon().getIconWidth(), button.getIcon().getIconHeight() ) ); - button.setBackground( Color.white ); - button.setBorderPainted( false ); - button.setFocusPainted( false ); - button.setContentAreaFilled( false ); - } - - @Override - public void singleMode() - { - fusion.getModel().setSelected( false ); - } - - @Override - public void fusedMode() - { - fusion.getModel().setSelected( true ); - } - - @Override - public void sourceMode() - { - grouping.getModel().setSelected( false ); - } - - @Override - public void groupMode() - { - grouping.getModel().setSelected( true ); - } - - @Override - public void interpolationMode( final Interpolation interpolation_mode ) - { - interpolation.setSelected( interpolation_mode == Interpolation.NLINEAR ); - } -} diff --git a/src/main/java/bdv/viewer/ViewerFrame.java b/src/main/java/bdv/viewer/ViewerFrame.java index 9ebb282c4..7af647e3b 100644 --- a/src/main/java/bdv/viewer/ViewerFrame.java +++ b/src/main/java/bdv/viewer/ViewerFrame.java @@ -106,7 +106,8 @@ public ViewerFrame( triggerbindings = new TriggerBehaviourBindings(); cards = new CardPanel(); - BdvDefaultCards.setup( cards, viewer, setups, triggerbindings ); + BdvDefaultCards.addOptions(cards, viewer, triggerbindings); + BdvDefaultCards.addSourcesAndGroups( cards, viewer, setups, triggerbindings ); splitPanel = new SplitPanel( viewer, cards ); getRootPane().setDoubleBuffered( true ); diff --git a/src/main/resources/bdv/ui/viewermodepanel/fusion_mode.png b/src/main/resources/bdv/ui/viewermodepanel/fusion_mode.png index 54f269379..cd2fd7e61 100644 Binary files a/src/main/resources/bdv/ui/viewermodepanel/fusion_mode.png and b/src/main/resources/bdv/ui/viewermodepanel/fusion_mode.png differ diff --git a/src/main/resources/bdv/ui/viewermodepanel/fusion_mode.svg b/src/main/resources/bdv/ui/viewermodepanel/fusion_mode.svg index 269640200..19db0b245 100644 --- a/src/main/resources/bdv/ui/viewermodepanel/fusion_mode.svg +++ b/src/main/resources/bdv/ui/viewermodepanel/fusion_mode.svg @@ -10,13 +10,13 @@ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="40" - height="53" - viewBox="0 0 10.583333 14.022918" + height="39.995888" + viewBox="0 0 10.583333 10.582246" version="1.1" id="svg8" inkscape:version="0.92.3 (2405546, 2018-03-11)" sodipodi:docname="fusion_mode.svg" - inkscape:export-filename="/home/tibuch/Gitrepos/bigdataviewer-core/src/main/resources/bdv/ui/viewermodepanel/fusion_mode.png" + inkscape:export-filename="/home/random/Development/imagej/bigdataviewer/bigdataviewer-core/src/main/resources/bdv/ui/viewermodepanel/fusion_mode.png" inkscape:export-xdpi="96" inkscape:export-ydpi="96"> + inkscape:window-y="33" + inkscape:window-maximized="1" + fit-margin-top="0" + fit-margin-left="0" + fit-margin-right="0" + fit-margin-bottom="0" /> @@ -57,66 +61,26 @@ inkscape:label="Layer 1" inkscape:groupmode="layer" id="layer1" - transform="translate(0,-282.97707)"> + transform="translate(-2.4093051e-8,-282.97707)"> - - - - - - - - + + + - Fused diff --git a/src/main/resources/bdv/ui/viewermodepanel/grouping_mode.png b/src/main/resources/bdv/ui/viewermodepanel/grouping_mode.png index 5625c9742..69aebc0bd 100644 Binary files a/src/main/resources/bdv/ui/viewermodepanel/grouping_mode.png and b/src/main/resources/bdv/ui/viewermodepanel/grouping_mode.png differ diff --git a/src/main/resources/bdv/ui/viewermodepanel/grouping_mode.svg b/src/main/resources/bdv/ui/viewermodepanel/grouping_mode.svg index c7a4376a6..96e2a171f 100644 --- a/src/main/resources/bdv/ui/viewermodepanel/grouping_mode.svg +++ b/src/main/resources/bdv/ui/viewermodepanel/grouping_mode.svg @@ -10,13 +10,13 @@ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="40" - height="53" - viewBox="0 0 10.583333 14.022918" + height="40" + viewBox="0 0 10.583333 10.583334" version="1.1" id="svg8" inkscape:version="0.92.3 (2405546, 2018-03-11)" sodipodi:docname="grouping_mode.svg" - inkscape:export-filename="/home/tibuch/Gitrepos/bigdataviewer-core/src/main/resources/bdv/ui/viewermodepanel/grouping_mode.png" + inkscape:export-filename="/home/random/Development/imagej/bigdataviewer/bigdataviewer-core/src/main/resources/bdv/ui/viewermodepanel/grouping_mode.png" inkscape:export-xdpi="96" inkscape:export-ydpi="96"> + inkscape:window-y="33" + inkscape:window-maximized="1" + fit-margin-top="0" + fit-margin-left="0" + fit-margin-right="0" + fit-margin-bottom="0" /> @@ -57,16 +61,21 @@ inkscape:label="Layer 1" inkscape:groupmode="layer" id="layer1" - transform="translate(0,-282.97707)"> + transform="translate(-5.555898e-5,-282.97696)"> + - - - - - Group diff --git a/src/main/resources/bdv/ui/viewermodepanel/linear.png b/src/main/resources/bdv/ui/viewermodepanel/linear.png index 6569a6b59..05c16670b 100644 Binary files a/src/main/resources/bdv/ui/viewermodepanel/linear.png and b/src/main/resources/bdv/ui/viewermodepanel/linear.png differ diff --git a/src/main/resources/bdv/ui/viewermodepanel/linear.svg b/src/main/resources/bdv/ui/viewermodepanel/linear.svg index 5dbccfd25..4ad05a119 100644 --- a/src/main/resources/bdv/ui/viewermodepanel/linear.svg +++ b/src/main/resources/bdv/ui/viewermodepanel/linear.svg @@ -11,13 +11,13 @@ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="40" - height="53" - viewBox="0 0 10.583333 14.022917" + height="40" + viewBox="0 0 10.583333 10.583334" version="1.1" id="svg8" inkscape:version="0.92.3 (2405546, 2018-03-11)" sodipodi:docname="linear.svg" - inkscape:export-filename="/home/tibuch/Gitrepos/bigdataviewer-core/src/main/resources/bdv/ui/viewermodepanel/linear.png" + inkscape:export-filename="/home/random/Development/imagej/bigdataviewer/bigdataviewer-core/src/main/resources/bdv/ui/viewermodepanel/linear.png" inkscape:export-xdpi="96" inkscape:export-ydpi="96"> @@ -43,7 +43,7 @@ x2="2.4347966" y2="284.99265" gradientUnits="userSpaceOnUse" - gradientTransform="matrix(0.82135526,0,0,0.82135526,2.0319129,52.584282)" /> + gradientTransform="matrix(0.82135529,0,0,0.82135529,2.0319136,52.584295)" /> + inkscape:window-y="33" + inkscape:window-maximized="1" + fit-margin-top="0" + fit-margin-left="0" + fit-margin-right="0" + fit-margin-bottom="0" /> @@ -73,7 +77,7 @@ image/svg+xml - + @@ -81,24 +85,15 @@ inkscape:label="Layer 1" inkscape:groupmode="layer" id="layer1" - transform="translate(0,-282.97707)"> + transform="translate(-6.9485441e-7,-282.97708)"> - Linear + width="6.0729942" + height="6.0729942" + x="2.2551703" + y="285.23227" + rx="0.48999995" + ry="0.48999995" /> diff --git a/src/main/resources/bdv/ui/viewermodepanel/nearest.png b/src/main/resources/bdv/ui/viewermodepanel/nearest.png index ebf99b0a7..40b4806a4 100644 Binary files a/src/main/resources/bdv/ui/viewermodepanel/nearest.png and b/src/main/resources/bdv/ui/viewermodepanel/nearest.png differ diff --git a/src/main/resources/bdv/ui/viewermodepanel/nearest.svg b/src/main/resources/bdv/ui/viewermodepanel/nearest.svg index 0c73bd726..79d86d5ac 100644 --- a/src/main/resources/bdv/ui/viewermodepanel/nearest.svg +++ b/src/main/resources/bdv/ui/viewermodepanel/nearest.svg @@ -10,12 +10,15 @@ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="40" - height="53" - viewBox="0 0 10.583333 14.022917" + height="40" + viewBox="0 0 10.583333 10.583334" version="1.1" id="svg8" inkscape:version="0.92.3 (2405546, 2018-03-11)" - sodipodi:docname="nearest.svg"> + sodipodi:docname="nearest.svg" + inkscape:export-filename="/home/random/Development/imagej/bigdataviewer/bigdataviewer-core/src/main/resources/bdv/ui/viewermodepanel/nearest.png" + inkscape:export-xdpi="96" + inkscape:export-ydpi="96"> + inkscape:window-y="33" + inkscape:window-maximized="1" + fit-margin-top="0" + fit-margin-left="0" + fit-margin-right="0" + fit-margin-bottom="0" /> @@ -46,7 +53,7 @@ image/svg+xml - + @@ -54,46 +61,11 @@ inkscape:label="Layer 1" inkscape:groupmode="layer" id="layer1" - transform="translate(0,-282.97707)"> - - - - - Nearest + transform="translate(-1.0335785e-4,-282.97696)"> + diff --git a/src/main/resources/bdv/ui/viewermodepanel/rotation_off.png b/src/main/resources/bdv/ui/viewermodepanel/rotation_off.png index c1e7271e3..6e31598af 100644 Binary files a/src/main/resources/bdv/ui/viewermodepanel/rotation_off.png and b/src/main/resources/bdv/ui/viewermodepanel/rotation_off.png differ diff --git a/src/main/resources/bdv/ui/viewermodepanel/rotation_off.svg b/src/main/resources/bdv/ui/viewermodepanel/rotation_off.svg index e639c96b2..8305669a6 100644 --- a/src/main/resources/bdv/ui/viewermodepanel/rotation_off.svg +++ b/src/main/resources/bdv/ui/viewermodepanel/rotation_off.svg @@ -16,7 +16,7 @@ id="svg8" inkscape:version="0.92.3 (2405546, 2018-03-11)" sodipodi:docname="rotation_off.svg" - inkscape:export-filename="/home/tibuch/Gitrepos/bigdataviewer-core/src/main/resources/bdv/ui/viewermodepanel/rotation_off.png" + inkscape:export-filename="/home/random/Development/imagej/bigdataviewer/bigdataviewer-core/src/main/resources/bdv/ui/viewermodepanel/rotation_off.png" inkscape:export-xdpi="96" inkscape:export-ydpi="96"> @@ -310,7 +310,7 @@ image/svg+xml - + @@ -320,8 +320,8 @@ id="layer1" transform="translate(0,-286.41665)"> diff --git a/src/main/resources/bdv/ui/viewermodepanel/rotation_on.png b/src/main/resources/bdv/ui/viewermodepanel/rotation_on.png index a88f9edae..63bb0b45f 100644 Binary files a/src/main/resources/bdv/ui/viewermodepanel/rotation_on.png and b/src/main/resources/bdv/ui/viewermodepanel/rotation_on.png differ diff --git a/src/main/resources/bdv/ui/viewermodepanel/rotation_on.svg b/src/main/resources/bdv/ui/viewermodepanel/rotation_on.svg index e1c1140e4..9f497c56c 100644 --- a/src/main/resources/bdv/ui/viewermodepanel/rotation_on.svg +++ b/src/main/resources/bdv/ui/viewermodepanel/rotation_on.svg @@ -16,7 +16,7 @@ id="svg8" inkscape:version="0.92.3 (2405546, 2018-03-11)" sodipodi:docname="rotation_on.svg" - inkscape:export-filename="/home/tibuch/Gitrepos/bigdataviewer-core/src/main/resources/bdv/ui/viewermodepanel/rotation_on.png" + inkscape:export-filename="/home/random/Development/imagej/bigdataviewer/bigdataviewer-core/src/main/resources/bdv/ui/viewermodepanel/rotation_on.png" inkscape:export-xdpi="96" inkscape:export-ydpi="96"> @@ -320,8 +320,8 @@ id="layer1" transform="translate(0,-286.41665)"> diff --git a/src/main/resources/bdv/ui/viewermodepanel/single_mode.png b/src/main/resources/bdv/ui/viewermodepanel/single_mode.png index 27efb49d8..5004a50d2 100644 Binary files a/src/main/resources/bdv/ui/viewermodepanel/single_mode.png and b/src/main/resources/bdv/ui/viewermodepanel/single_mode.png differ diff --git a/src/main/resources/bdv/ui/viewermodepanel/single_mode.svg b/src/main/resources/bdv/ui/viewermodepanel/single_mode.svg index 11abe359c..3a639cba9 100644 --- a/src/main/resources/bdv/ui/viewermodepanel/single_mode.svg +++ b/src/main/resources/bdv/ui/viewermodepanel/single_mode.svg @@ -10,13 +10,13 @@ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="40" - height="53" - viewBox="0 0 10.583333 14.022919" + height="40" + viewBox="0 0 10.583333 10.583336" version="1.1" id="svg8" inkscape:version="0.92.3 (2405546, 2018-03-11)" sodipodi:docname="single_mode.svg" - inkscape:export-filename="/home/tibuch/Gitrepos/bigdataviewer-core/src/main/resources/bdv/ui/viewermodepanel/single_mode.png" + inkscape:export-filename="/home/random/Development/imagej/bigdataviewer/bigdataviewer-core/src/main/resources/bdv/ui/viewermodepanel/single_mode.png" inkscape:export-xdpi="96" inkscape:export-ydpi="96"> + inkscape:window-y="33" + inkscape:window-maximized="0" + fit-margin-top="0" + fit-margin-left="0" + fit-margin-right="0" + fit-margin-bottom="0" /> @@ -57,17 +61,17 @@ inkscape:label="Layer 1" inkscape:groupmode="layer" id="layer1" - transform="translate(0,-282.97706)"> + transform="translate(-2.7536975e-5,-282.97592)"> - - Single diff --git a/src/main/resources/bdv/ui/viewermodepanel/source_mode.png b/src/main/resources/bdv/ui/viewermodepanel/source_mode.png index a7bcf8431..0c4bc54bd 100644 Binary files a/src/main/resources/bdv/ui/viewermodepanel/source_mode.png and b/src/main/resources/bdv/ui/viewermodepanel/source_mode.png differ diff --git a/src/main/resources/bdv/ui/viewermodepanel/source_mode.svg b/src/main/resources/bdv/ui/viewermodepanel/source_mode.svg index c5fd6dbfe..6e967781c 100644 --- a/src/main/resources/bdv/ui/viewermodepanel/source_mode.svg +++ b/src/main/resources/bdv/ui/viewermodepanel/source_mode.svg @@ -10,13 +10,13 @@ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="40" - height="53" - viewBox="0 0 10.583333 14.022918" + height="40" + viewBox="0 0 10.583333 10.583334" version="1.1" id="svg8" inkscape:version="0.92.3 (2405546, 2018-03-11)" sodipodi:docname="source_mode.svg" - inkscape:export-filename="/home/tibuch/Gitrepos/bigdataviewer-core/src/main/resources/bdv/ui/viewermodepanel/source_mode.png" + inkscape:export-filename="/home/random/Development/imagej/bigdataviewer/bigdataviewer-core/src/main/resources/bdv/ui/viewermodepanel/source_mode.png" inkscape:export-xdpi="96" inkscape:export-ydpi="96"> + inkscape:window-y="33" + inkscape:window-maximized="1" + fit-margin-top="0" + fit-margin-left="0" + fit-margin-right="0" + fit-margin-bottom="0" /> @@ -57,7 +61,7 @@ inkscape:label="Layer 1" inkscape:groupmode="layer" id="layer1" - transform="translate(0,-282.97707)"> + transform="translate(1.9123157e-7,-282.97707)"> @@ -69,7 +73,7 @@ height="4.6323395" width="4.6327744" id="rect815" - style="opacity:1;fill:none;fill-opacity:0.4545455;fill-rule:nonzero;stroke:#000000;stroke-width:0.141;stroke-miterlimit:4;stroke-dasharray:0.564, 0.564;stroke-dashoffset:0;stroke-opacity:1" /> + style="opacity:1;fill:#2e2e2e;fill-opacity:0.19844358;fill-rule:nonzero;stroke:#000000;stroke-width:0.141;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> - - - - + style="opacity:1;fill:#484848;fill-opacity:0.45136186;fill-rule:nonzero;stroke:#000000;stroke-width:0.141;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> + ry="0.27094325" + rx="0.27096879" + y="282.73801" + x="-72.2089" + height="4.6081691" + width="4.6086035" + id="rect815-3" + style="opacity:1;fill:none;fill-opacity:0.10894943;fill-rule:nonzero;stroke:#000000;stroke-width:0.14111109;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + transform="rotate(-15.000005)" /> + - Source diff --git a/src/main/resources/bdv/ui/viewermodepanel/translation_off.png b/src/main/resources/bdv/ui/viewermodepanel/translation_off.png index 176b69fef..e34a4c023 100644 Binary files a/src/main/resources/bdv/ui/viewermodepanel/translation_off.png and b/src/main/resources/bdv/ui/viewermodepanel/translation_off.png differ diff --git a/src/main/resources/bdv/ui/viewermodepanel/translation_off.svg b/src/main/resources/bdv/ui/viewermodepanel/translation_off.svg index 0ea573eb9..6852b38e2 100644 --- a/src/main/resources/bdv/ui/viewermodepanel/translation_off.svg +++ b/src/main/resources/bdv/ui/viewermodepanel/translation_off.svg @@ -16,7 +16,7 @@ id="svg8" inkscape:version="0.92.3 (2405546, 2018-03-11)" sodipodi:docname="translation_off.svg" - inkscape:export-filename="/home/tibuch/Gitrepos/bigdataviewer-core/src/main/resources/bdv/ui/viewermodepanel/translation_off.png" + inkscape:export-filename="/home/random/Development/imagej/bigdataviewer/bigdataviewer-core/src/main/resources/bdv/ui/viewermodepanel/translation_off.png" inkscape:export-xdpi="96" inkscape:export-ydpi="96"> @@ -194,7 +194,7 @@ image/svg+xml - + @@ -204,8 +204,8 @@ id="layer1" transform="translate(0,-286.41665)"> diff --git a/src/main/resources/bdv/ui/viewermodepanel/translation_on.png b/src/main/resources/bdv/ui/viewermodepanel/translation_on.png index 74a06b119..5e989bd35 100644 Binary files a/src/main/resources/bdv/ui/viewermodepanel/translation_on.png and b/src/main/resources/bdv/ui/viewermodepanel/translation_on.png differ diff --git a/src/main/resources/bdv/ui/viewermodepanel/translation_on.svg b/src/main/resources/bdv/ui/viewermodepanel/translation_on.svg index 9635a96a8..92c29227d 100644 --- a/src/main/resources/bdv/ui/viewermodepanel/translation_on.svg +++ b/src/main/resources/bdv/ui/viewermodepanel/translation_on.svg @@ -16,7 +16,7 @@ id="svg8" inkscape:version="0.92.3 (2405546, 2018-03-11)" sodipodi:docname="translation_on.svg" - inkscape:export-filename="/home/tibuch/Gitrepos/bigdataviewer-core/src/main/resources/bdv/ui/viewermodepanel/translation_on.png" + inkscape:export-filename="/home/random/Development/imagej/bigdataviewer/bigdataviewer-core/src/main/resources/bdv/ui/viewermodepanel/translation_on.png" inkscape:export-xdpi="96" inkscape:export-ydpi="96"> @@ -194,7 +194,7 @@ image/svg+xml - + @@ -204,8 +204,8 @@ id="layer1" transform="translate(0,-286.41665)"> diff --git a/src/test/java/bdv/ui/AnnotatedToggleGroupButtonExample.java b/src/test/java/bdv/ui/AnnotatedToggleGroupButtonExample.java new file mode 100644 index 000000000..d5b2a41a4 --- /dev/null +++ b/src/test/java/bdv/ui/AnnotatedToggleGroupButtonExample.java @@ -0,0 +1,59 @@ +package bdv.ui; + +import bdv.ui.iconcards.options.AnnotatedToggleGroupButton; +import bdv.ui.iconcards.options.ToggleGroupButton; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Image; +import java.util.ArrayList; +import java.util.List; +import javax.swing.Icon; +import javax.swing.ImageIcon; +import javax.swing.JFrame; +import javax.swing.WindowConstants; +import net.miginfocom.swing.MigLayout; + +public class AnnotatedToggleGroupButtonExample +{ + public static void main( String[] args ) + { + System.setProperty( "apple.laf.useScreenMenuBar", "true" ); + + final JFrame frame = new JFrame( "ToggleGroupButton Example" ); + frame.setLayout( new MigLayout( "ins 0, fillx, filly", "[grow]", "" ) ); + + final Image rotation_on = new ImageIcon( frame.getClass().getResource( "/bdv/ui/viewermodepanel/rotation_on.png" ) ).getImage().getScaledInstance( 40, 40, Image.SCALE_SMOOTH ); + final Image rotation_off = new ImageIcon( frame.getClass().getResource( "/bdv/ui/viewermodepanel/rotation_off.png" ) ).getImage().getScaledInstance( 40, 40, Image.SCALE_SMOOTH ); + final Image translation_on = new ImageIcon( frame.getClass().getResource( "/bdv/ui/viewermodepanel/translation_on.png" ) ).getImage().getScaledInstance( 40, 40, Image.SCALE_SMOOTH ); + final Image translation_off = new ImageIcon( frame.getClass().getResource( "/bdv/ui/viewermodepanel/translation_off.png" ) ).getImage().getScaledInstance( 40, 40, Image.SCALE_SMOOTH ); + + final List< Icon > icons = new ArrayList<>(); + icons.add( new ImageIcon( rotation_on ) ); + icons.add( new ImageIcon( rotation_off ) ); + final List< String > labels = new ArrayList<>(); + labels.add( "Rotation On" ); + labels.add( "Rotation Off" ); + final List< Runnable > actions = new ArrayList<>(); + actions.add( () -> System.out.println( "Rotation On" ) ); + actions.add( () -> System.out.println( "Rotation Off" ) ); + + final List< String > annotations = new ArrayList<>( ); + annotations.add( "Rot. On" ); + annotations.add( "Rot. Off" ); + + final AnnotatedToggleGroupButton button = new AnnotatedToggleGroupButton( icons, labels, actions, annotations ); + button.setAnnotationFont( new Font( button.getFont().getName(), Font.TRUETYPE_FONT, 9 ) ); + + button.addOption( new ImageIcon( translation_on ), "Translation On", () -> System.out.println( "Translation On" ), "Trans. On" ); + button.addOption( new ImageIcon( translation_off ), "Uups", () -> System.out.println( "uups" ), "Ups" ); + button.removeOption( "Uups" ); + button.addOption( new ImageIcon( translation_off ), "Translation Off", () -> System.out.println( "Translation Off" ), "Trans. Off" ); + + button.setPreferredSize( new Dimension( 40, 40 ) ); + frame.add( button, "growx, growy" ); + frame.pack(); + frame.setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE ); + frame.setVisible( true ); + } +} + diff --git a/src/test/java/bdv/ui/ToggleGroupButtonExample.java b/src/test/java/bdv/ui/ToggleGroupButtonExample.java new file mode 100644 index 000000000..a40b40873 --- /dev/null +++ b/src/test/java/bdv/ui/ToggleGroupButtonExample.java @@ -0,0 +1,52 @@ +package bdv.ui; + +import bdv.ui.iconcards.options.ToggleGroupButton; +import java.awt.Dimension; +import java.awt.Image; +import java.util.ArrayList; +import java.util.List; +import javax.swing.Icon; +import javax.swing.ImageIcon; +import javax.swing.JFrame; +import javax.swing.WindowConstants; +import net.miginfocom.swing.MigLayout; + +public class ToggleGroupButtonExample +{ + public static void main( String[] args ) + { + System.setProperty( "apple.laf.useScreenMenuBar", "true" ); + + final JFrame frame = new JFrame( "ToggleGroupButton Example" ); + frame.setLayout( new MigLayout( "ins 0, fillx, filly", "[grow]", "" ) ); + + final Image rotation_on = new ImageIcon( frame.getClass().getResource( "/bdv/ui/viewermodepanel/rotation_on.png" ) ).getImage().getScaledInstance( 40, 40, Image.SCALE_SMOOTH ); + final Image rotation_off = new ImageIcon( frame.getClass().getResource( "/bdv/ui/viewermodepanel/rotation_off.png" ) ).getImage().getScaledInstance( 40, 40, Image.SCALE_SMOOTH ); + final Image translation_on = new ImageIcon( frame.getClass().getResource( "/bdv/ui/viewermodepanel/translation_on.png" ) ).getImage().getScaledInstance( 40, 40, Image.SCALE_SMOOTH ); + final Image translation_off = new ImageIcon( frame.getClass().getResource( "/bdv/ui/viewermodepanel/translation_off.png" ) ).getImage().getScaledInstance( 40, 40, Image.SCALE_SMOOTH ); + + final List< Icon > icons = new ArrayList<>(); + icons.add( new ImageIcon( rotation_on ) ); + icons.add( new ImageIcon( rotation_off ) ); + final List< String > labels = new ArrayList<>(); + labels.add( "Rotation On" ); + labels.add( "Rotation Off" ); + final List< Runnable > actions = new ArrayList<>(); + actions.add( () -> System.out.println( "Rotation On" ) ); + actions.add( () -> System.out.println( "Rotation Off" ) ); + + final ToggleGroupButton button = new ToggleGroupButton( icons, labels, actions ); + + button.addOption( new ImageIcon( translation_on ), "Translation On", () -> System.out.println( "Translation On" ) ); + button.addOption( new ImageIcon( translation_off ), "Uups", () -> System.out.println( "uups" ) ); + button.removeOption( "Uups" ); + button.addOption( new ImageIcon( translation_off ), "Translation Off", () -> System.out.println( "Translation Off" ) ); + + button.setPreferredSize( new Dimension( 40, 40 ) ); + frame.add( button, "growx, growy" ); + frame.pack(); + frame.setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE ); + frame.setVisible( true ); + } +} +