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

Source Info Tool Bar and Location Card #167

Open
wants to merge 13 commits into
base: master
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
3 changes: 3 additions & 0 deletions src/main/java/bdv/ui/BdvDefaultCards.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import bdv.viewer.AbstractViewerPanel;
import bdv.viewer.ConverterSetups;
import bdv.viewer.ViewerState;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
Expand Down Expand Up @@ -63,6 +64,8 @@ public class BdvDefaultCards

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

public static final String DEFAULT_LOCATIONS_CARD = "default bdv locations card";

public static void setup( final CardPanel cards, final AbstractViewerPanel viewer, final ConverterSetups converterSetups )
{
final ViewerState state = viewer.state();
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/bdv/ui/appearance/Appearance.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class Appearance
private int scaleBarColor = 0xffffffff;
private int scaleBarBgColor = 0x88000000;
private LookAndFeelInfo lookAndFeel = DONT_MODIFY_LOOK_AND_FEEL;
private boolean showSourceInfoToolBar = false;

public interface UpdateListener
{
Expand All @@ -81,6 +82,7 @@ public void set( final Appearance other )
this.scaleBarColor = other.scaleBarColor;
this.scaleBarBgColor = other.scaleBarBgColor;
this.lookAndFeel = other.lookAndFeel;
this.showSourceInfoToolBar = other.showSourceInfoToolBar;
notifyListeners();
}

Expand Down Expand Up @@ -222,6 +224,15 @@ public static LookAndFeelInfo lookAndFeelInfoForName( final String name )
return DONT_MODIFY_LOOK_AND_FEEL;
}

public boolean showSourceInfoToolBar() {
return showSourceInfoToolBar;
}

public void setShowSourceInfoToolBar(final boolean showSourceInfoToolBar) {
this.showSourceInfoToolBar = showSourceInfoToolBar;
notifyListeners();
}

@Override
public String toString()
{
Expand All @@ -234,6 +245,7 @@ public String toString()
sb.append( ", scaleBarColor=" ).append( scaleBarColor );
sb.append( ", scaleBarBgColor=" ).append( scaleBarBgColor );
sb.append( ", lookAndFeel=" ).append( lookAndFeel );
sb.append( ", showSourceInfoToolBar=" ).append(showSourceInfoToolBar);
sb.append( '}' );
return sb.toString();
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/bdv/ui/appearance/AppearanceIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public Node representData( final Object data )
mapping.put( "scaleBarColor", hex( a.scaleBarColor() ) );
mapping.put( "scaleBarBgColor", hex( a.scaleBarBgColor() ) );
mapping.put( "lookAndFeel", a.lookAndFeel() );
mapping.put( "showSourceInfoToolBar", a.showSourceInfoToolBar() );
return representMapping( APPEARANCE_TAG, mapping, getDefaultFlowStyle() );
}
}
Expand Down Expand Up @@ -178,6 +179,7 @@ public Object construct( final Node node )
a.setScaleBarColor( hexColor( mapping.get( "scaleBarColor" ) ) );
a.setScaleBarBgColor( hexColor( mapping.get( "scaleBarBgColor" ) ) );
a.setLookAndFeel( ( LookAndFeelInfo ) mapping.get( "lookAndFeel" ) );
a.setShowSourceInfoToolBar(( Boolean ) mapping.get("showSourceInfoToolBar" ) );
return a;
}
catch( final Exception e )
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/bdv/ui/appearance/AppearanceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ public void toPrefs()
Prefs.sourceNameOverlayPosition( appearance.sourceNameOverlayPosition() );
Prefs.scaleBarColor( appearance.scaleBarColor() );
Prefs.scaleBarBgColor( appearance.scaleBarBgColor() );
}
Prefs.showSourceInfoToolBar( appearance.showSourceInfoToolBar() );
}

/**
* @deprecated Prefs will be replaced eventually by directly using {@code Appearance} in BDV
Expand All @@ -194,5 +195,6 @@ public void fromPrefs()
appearance.setSourceNameOverlayPosition( Prefs.sourceNameOverlayPosition() );
appearance.setScaleBarColor( Prefs.scaleBarColor() );
appearance.setScaleBarBgColor( Prefs.scaleBarBgColor() );
appearance.setShowSourceInfoToolBar(Prefs.showSourceInfoToolBar() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public AppearancePanel( final Appearance appearance )
booleanElement( "show scalebar in movies", appearance::showScaleBarInMovie, appearance::setShowScaleBarInMovie ),
colorElement( "scalebar foreground", appearance::scaleBarColor, appearance::setScaleBarColor ),
colorElement( "scalebar background", appearance::scaleBarBgColor, appearance::setScaleBarBgColor ),
booleanElement("show source info tool bar", appearance::showSourceInfoToolBar, appearance::setShowSourceInfoToolBar),
separator(),
booleanElement( "show minimap", appearance::showMultibox, appearance::setShowMultibox ),
booleanElement( "show source info", appearance::showTextOverlay, appearance::setShowTextOverlay ),
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/bdv/util/Prefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public static boolean showScaleBar()
return getInstance().showScaleBar;
}

public static boolean showSourceInfoToolBar()
{
return getInstance().showSourceInfoToolBar;
}

public static boolean showMultibox()
{
return getInstance().showMultibox;
Expand Down Expand Up @@ -108,6 +113,11 @@ public static void scaleBarBgColor( final int color )
getInstance().scaleBarBgColor = color;
}

public static void showSourceInfoToolBar(final boolean show )
{
getInstance().showSourceInfoToolBar = show;
}

private static Prefs instance;

public static Prefs getInstance()
Expand All @@ -132,14 +142,15 @@ public enum OverlayPosition
private static final String SHOW_SCALE_BAR_IN_MOVIE = "show-scale-bar-in-movie";
private static final String SCALE_BAR_COLOR = "scale-bar-color";
private static final String SCALE_BAR_BG_COLOR = "scale-bar-bg-color";

private static final String SHOW_SOURCE_INFO_TOOL_BAR = "show-source-info-tool-bar";
private boolean showScaleBar;
private boolean showMultibox;
private boolean showTextOverlay;
private OverlayPosition sourceNameOverlayPosition;
private boolean showScaleBarInMovie;
private int scaleBarColor;
private int scaleBarBgColor;
private boolean showSourceInfoToolBar;

private Prefs( final Properties p )
{
Expand All @@ -150,6 +161,7 @@ private Prefs( final Properties p )
showScaleBarInMovie = getBoolean( p, SHOW_SCALE_BAR_IN_MOVIE, false );
scaleBarColor = getInt( p, SCALE_BAR_COLOR, 0xffffffff );
scaleBarBgColor = getInt( p, SCALE_BAR_BG_COLOR, 0x88000000 );
showSourceInfoToolBar = getBoolean(p, SHOW_SOURCE_INFO_TOOL_BAR, false );
}

private boolean getBoolean( final Properties p, final String key, final boolean defaultValue )
Expand Down Expand Up @@ -244,6 +256,7 @@ public static Properties getDefaultProperties()
properties.put( SHOW_SCALE_BAR_IN_MOVIE, "" + prefs.showScaleBarInMovie );
properties.put( SCALE_BAR_COLOR, "" + prefs.scaleBarColor );
properties.put( SCALE_BAR_BG_COLOR, "" + prefs.scaleBarBgColor );
properties.put( SHOW_SOURCE_INFO_TOOL_BAR, "" + prefs.showSourceInfoToolBar );
return properties;
}

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/bdv/viewer/ViewerFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import bdv.ui.CardPanel;
import bdv.ui.splitpanel.SplitPanel;
import bdv.util.AWTUtils;
import bdv.viewer.location.SourceInfoToolbarAndLocationCardManager;

/**
* A {@link JFrame} containing a {@link ViewerPanel} and associated
Expand Down Expand Up @@ -123,6 +124,11 @@ public ViewerFrame(
BdvDefaultCards.setup( cards, viewer, setups );
splitPanel = new SplitPanel( viewer, cards );

final SourceInfoToolbarAndLocationCardManager manager =
new SourceInfoToolbarAndLocationCardManager(appearanceManager, viewer);
manager.addToolbarToViewerFrame(this);
manager.addLocationCardToSplitPanel(splitPanel, cards);

getRootPane().setDoubleBuffered( true );
// add( viewer, BorderLayout.CENTER );
add( splitPanel, BorderLayout.CENTER );
Expand Down
30 changes: 29 additions & 1 deletion src/main/java/bdv/viewer/ViewerPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,14 @@ public void displayToGlobalCoordinates( final double x, final double y, final Re
state.getViewerTransform().applyInverse( gPos, lPos );
}

public double[] getDisplayCenterCoordinates() {
return new double[] {
getDisplay().getWidth() / 2.0,
getDisplay().getHeight() / 2.0,
0.0
};
}

@Override
public void paint()
{
Expand Down Expand Up @@ -513,7 +521,7 @@ public void drawOverlays( final Graphics g )
requiresRepaint = multiBoxOverlayRenderer.isHighlightInProgress();
}

if ( Prefs.showTextOverlay() )
if ( Prefs.showTextOverlay() && (! Prefs.showSourceInfoToolBar()) )
{
final Font font = UIUtils.getFont( "monospaced.small.font" );
sourceInfoOverlayRenderer.setViewerState( state );
Expand Down Expand Up @@ -1033,4 +1041,24 @@ public DebugTilingOverlay showDebugTileOverlay()
display.overlays().add( overlay );
return overlay;
}

/** Centers the viewer at the given global position in the specified dimension. */
public void centerViewAt(final double globalPosition,
final int dimension) {

// NOTE: getViewerTransform() transforms from global to display (window) coordinates
final double[] displayCenter = getDisplayCenterCoordinates();
final double[] gCenterPos = new double[3];
state().getViewerTransform().applyInverse(gCenterPos, displayCenter);

final double deltaPos = gCenterPos[dimension] - globalPosition;

final AffineTransform3D invertedViewerTransform = state().getViewerTransform().inverse();
final double q = invertedViewerTransform.get(dimension, 3) - deltaPos;
invertedViewerTransform.set(q, dimension, 3);

final AffineTransform3D updatedViewerTransform = invertedViewerTransform.inverse();
state().setViewerTransform(updatedViewerTransform);
}

}
Loading