Skip to content

Commit

Permalink
Merge pull request ome#5000 from dominikl/scale_bar_bigimages
Browse files Browse the repository at this point in the history
Zoom scale bar
  • Loading branch information
jburel authored Jan 4, 2017
2 parents 0580adc + f396e2a commit 47f8586
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,32 @@ public static int getValue(int index)
return values[index];
}

/**
* Returns the index corresponding to the passed value or
* <code>CUSTOMIZED</code>.
*
* @param value
* The value to handle.
* @return See above.
*/
public static int getIndex(double value) {
if (value < values[TWO])
return ONE;
if (value < values[FIVE])
return TWO;
if (value < values[TEN])
return FIVE;
if (value < values[TWENTY])
return TEN;
if (value < values[FIFTY])
return TWENTY;
if (value < values[HUNDRED])
return FIFTY;
if (value < 1000)
return HUNDRED;
return CUSTOMIZED;
}

/** One of the constant defined by this class. */
private int index;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* org.openmicroscopy.shoola.agents.imviewer.browser.Browser
*
*------------------------------------------------------------------------------
* Copyright (C) 2006-2015 University of Dundee. All rights reserved.
* Copyright (C) 2006-2016 University of Dundee. All rights reserved.
*
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -30,6 +30,7 @@
import javax.swing.Icon;
import javax.swing.JComponent;

import omero.model.Length;
import omero.model.enums.UnitsLength;
import org.openmicroscopy.shoola.agents.imviewer.view.ImViewer;
import org.openmicroscopy.shoola.util.ui.component.ObservableComponent;
Expand Down Expand Up @@ -419,4 +420,19 @@ public interface Browser
*/
public void setInterpolation(boolean interpolation);

/**
* Set the zoom factor for the selected resolution level
*
* @param ratio
* The zoom factor
*/
void setSelectedResolutionLevelZoomFactor(double ratio);

/**
* Get the length of the scale bar
*
* @return See above
*/
public Length getUnitBarLength();

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* org.openmicroscopy.shoola.agents.imviewer.browser.BrowserComponent
*
*------------------------------------------------------------------------------
* Copyright (C) 2006-2015 University of Dundee. All rights reserved.
* Copyright (C) 2006-2016 University of Dundee. All rights reserved.
*
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -32,6 +32,7 @@
import javax.swing.Icon;
import javax.swing.JComponent;

import omero.model.Length;
import omero.model.enums.UnitsLength;
import org.openmicroscopy.shoola.agents.imviewer.ImViewerAgent;
import org.openmicroscopy.shoola.agents.imviewer.actions.ZoomAction;
Expand Down Expand Up @@ -257,6 +258,15 @@ else if (index == ImViewer.PROJECTION_INDEX)
}
}

/**
* Implemented as specified by the {@link Browser} interface.
*
* @see Browser#setSelectedResolutionLevelZoomFactor(double)
*/
public void setSelectedResolutionLevelZoomFactor(double ratio) {
model.setZoomFactor(ratio);
}

/**
* Implemented as specified by the {@link Browser} interface.
* @see Browser#getZoomFactor()
Expand Down Expand Up @@ -675,5 +685,13 @@ public void setInterpolation(boolean interpolation) {
model.setInterpolation(interpolation);
paintImage();
}


/**
* Implemented as specified by the {@link Browser} interface.
*
* @see Browser#getUnitBarLength()
*/
public Length getUnitBarLength() {
return model.getUnitBarLength();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*------------------------------------------------------------------------------
* Copyright (C) 2006-2015 University of Dundee. All rights reserved.
* Copyright (C) 2006-2016 University of Dundee. All rights reserved.
*
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -407,7 +407,6 @@ private double getBarSizeInPx(double ratio)
*
* @param parent The parent of this component.
* Mustn't be <code>null</code>.
* @param imageID The id of the image.
* @param pref The preferences for the viewer.
*/
BrowserModel(ImViewer parent, ViewerPreferences pref)
Expand Down Expand Up @@ -663,43 +662,56 @@ void createDisplayedProjectedImage()
/**
* Sets the value of the flag controlling if the unit bar is painted or not.
*
* @param unitBar Pass <code>true</code> to paint the unit bar,
* <code>false</code> otherwise.
* @param unitBar
* Pass <code>true</code> to paint the unit bar,
* <code>false</code> otherwise.
*/
void setUnitBar(boolean unitBar)
{
void setUnitBar(boolean unitBar) {
if (unitBar) {
int unitBarLenghtValue = UnitBarSizeAction.getDefaultValue();
// Guess the unit to use by assuming a 100px wide scalebar
Length tmp = new LengthI(getPixelsSizeX().getValue() * 100,
// Determine a reasonable unit
Length tmp = new LengthI(getPixelsSizeX().getValue() / zoomFactor,
getPixelsSizeX().getUnit());
tmp = UIUtilities.transformSize(tmp);
this.unitBarLength = new LengthI(unitBarLenghtValue, tmp.getUnit());
UnitsLength unit = tmp.getUnit();

// Determine a reasonable size by assuming a scalebar with length of
// up to 1/5th of current image display size
Rectangle visSize = ((BrowserUI)component.getUI()).getVisibleRect();
int barLengthInPx = (int)(visSize.getWidth() / 5d);
tmp = new LengthI(getPixelsSizeX().getValue() * barLengthInPx
/ zoomFactor, getPixelsSizeX().getUnit());
try {
tmp = new LengthI(tmp, unit);
} catch (BigResult e) {
}

if (tmp.getValue() > 999) {
int dec = (int) Math.log10(tmp.getValue());
this.unitBarLength = new LengthI(Math.pow(10, dec),
tmp.getUnit());
} else {
int index = UnitBarSizeAction.getIndex(tmp.getValue());
this.unitBarLength = new LengthI(
UnitBarSizeAction.getValue(index), tmp.getUnit());
}

this.parent.updateUnitBarMenu(this.unitBarLength);
}
this.unitBar = unitBar;
this.unitBar = unitBar;
}

/**
* Sets the size of the unit bar.
*
* @param size
* The size of the unit bar.
* @param unit The unit
* @param unit
* The unit
*/
void setUnitBarSize(double size, UnitsLength unit) {
if (unitBarLength != null) {
try {
LengthI tmp = new LengthI(size, unit);
tmp = new LengthI(tmp, unitBarLength.getUnit());
unitBarLength.setValue(tmp.getValue());
} catch (BigResult e) {
}
}
else {
unitBarLength = new LengthI(size, unit);
}
unitBarLength = new LengthI(size, unit);
}

/**
* Returns the unit used to determine the size of the unit bar. The unit
* depends on the size stored. The unit of reference in the OME model is in
Expand Down Expand Up @@ -887,9 +899,14 @@ void setSelectedXYPlane(int z, int t)
*/
Length getPixelsSizeZ() { return parent.getPixelsSizeZ(); }

Length getUnitBarLength() {
return unitBarLength;
}
/**
* Get the length of the unit bar
*
* @return See above.
*/
public Length getUnitBarLength() {
return unitBarLength;
}

/**
* Returns the number of column for the grid.
Expand Down Expand Up @@ -1261,7 +1278,7 @@ boolean isInterpolation() {
* En-/Disables interpolation; value will be stored in user
* preferences
*
* @param interpolation
* @param interpolation The interpolation flag
*/
void setInterpolation(boolean interpolation) {
ImViewerFactory.setInterpolation(interpolation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ void paintScaleBar(Graphics2D g2D, int width, int height,
Rectangle imgRect = new Rectangle(0, 0, width, height);
Rectangle viewRect = viewPort.getBounds();
Point p = viewPort.getViewPosition();
int x = (int) p.getX();
int y = (int) p.getY();
int x = viewPort.getWidth() > width ? 0 : (int) p.getX();
int y = viewPort.getHeight() > height ? height : (int) p.getY();
int w = Math.min(x+viewRect.width, width);
int h = Math.min(y+viewRect.height, height);
if (imgRect.contains(viewRect)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1396,4 +1396,12 @@ public void setProjectedImage(ImageData image, List<Integer> indexes,
*/
void reloadROICount();

/**
* Update the scale bar menu, according to the given length
*
* @param unitBarLength
* The current scale bar length
*/
public void updateUnitBarMenu(Length unitBarLength);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3566,4 +3566,14 @@ void onSettingsChanged()
public void reloadROICount() {
model.reloadROICount();
}

/**
* Implemented as specified by the {@link ImViewer} interface.
*
* @see ImViewer#updateUnitBarMenu(Length)
*/
public void updateUnitBarMenu(Length unitBarLength) {
view.setScaleBarLength(unitBarLength);
model.setScaleBarUnit(unitBarLength.getUnit());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,16 @@ public UnitsLength getScaleBarUnit() {
}
return scaleBarUnit;
}

/**
* Set the unit used for the scalebar
*
* @param unit
* The unit
*/
public void setScaleBarUnit(UnitsLength unit) {
this.scaleBarUnit = unit;
}

/**
* Returns the current user's details.
Expand Down Expand Up @@ -2936,6 +2946,8 @@ void setSelectedResolutionLevel(int level)
tiles.clear();
rnd.setSelectedResolutionLevel(level);
initializeTiles();

browser.setSelectedResolutionLevelZoomFactor(getResolutionDescription().getRatio());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2177,6 +2177,35 @@ int getScaleBarIndex()
return -1;
}

/**
* Set the scale bar index
*
* @param unitBarLength
* The scale bar length.
*/
void setScaleBarLength(Length unitBarLength) {

scaleBarMenu.setText(SCALE_BAR_TEXT
+ LengthI.lookupSymbol(unitBarLength.getUnit()) + ")");

int index = UnitBarSizeAction.CUSTOMIZED;
if (unitBarLength.getValue() < 999) {
index = UnitBarSizeAction.getIndex(unitBarLength.getValue());
}

if (scaleBarGroup == null)
return;
JCheckBoxMenuItem item;
Enumeration e;
for (e = scaleBarGroup.getElements(); e.hasMoreElements();) {
item = (JCheckBoxMenuItem) e.nextElement();
if (((UnitBarSizeAction) item.getAction()).getIndex() == index)
item.setSelected(true);
else
item.setSelected(false);
}
}

/** Shows the list of users who viewed the image. */
void showUsersList()
{
Expand Down

0 comments on commit 47f8586

Please sign in to comment.