Skip to content

Commit

Permalink
Fixed Scrollbar bug in ImgCanvas
Browse files Browse the repository at this point in the history
	* Since now this is a workaround
	* Maybe there exists a better solution
  • Loading branch information
dietzc committed Dec 5, 2013
1 parent 902abbf commit 556d54b
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
import org.knime.knip.core.ui.imgviewer.events.ViewZoomfactorChgEvent;
import org.knime.knip.core.ui.imgviewer.panels.MinimapPanel;

import edu.mines.jtk.util.Array;

/**
*
* Panel to draw a BufferedImage.
Expand Down Expand Up @@ -152,6 +154,9 @@ public class ImgCanvas<T extends Type<T>, I extends IterableInterval<T> & Random

protected EventService m_eventService;

//TODO Workaround
private boolean m_init;

public ImgCanvas() {
this("Image", false);
}
Expand Down Expand Up @@ -352,14 +357,21 @@ private void fireImageCoordMouseMoved(final MouseEvent e) {

@EventListener
public void onZoomFactorChanged(final ViewZoomfactorChgEvent zoomEvent) {
if (m_zoomFactor == zoomEvent.getZoomFactor()) {
return;
}
m_zoomFactor = zoomEvent.getZoomFactor();
updateImageCanvas();
}

@EventListener
public void onCalibrationUpdateEvent(final CalibrationUpdateEvent e) {
m_scaleFactors =
double[] newFactors =
new double[]{e.getScaleFactors()[e.getSelectedDims()[0]], e.getScaleFactors()[e.getSelectedDims()[1]],};
if (Array.equal(newFactors, m_scaleFactors)) {
return;
}
m_scaleFactors = newFactors;
updateImageCanvas();
}

Expand All @@ -380,6 +392,7 @@ public void onMinimapOffsetChanged(final MinimapOffsetChgEvent e) {
@EventListener
public void onBufferedImageChanged(final AWTImageChgEvent e) {
m_image = (BufferedImage)e.getImage();
m_init = true;
m_blockMouseEvents = false;

updateImageCanvas();
Expand All @@ -394,10 +407,11 @@ protected void updateImageCanvas() {
m_factors[0] = m_scaleFactors[0] * m_zoomFactor;
m_factors[1] = m_scaleFactors[1] * m_zoomFactor;

if (m_oldFactors[0] != m_factors[0] || m_oldFactors[1] != m_factors[1]) {
if (m_oldFactors[0] != m_factors[0] || m_oldFactors[1] != m_factors[1] || m_init) {
// TODO: Workaround
m_init=false;

// get old center of the image

final Rectangle rect = m_imageCanvas.getVisibleRect();
final double imgCenterX = rect.getCenterX() / m_oldFactors[0];
final double imgCenterY = rect.getCenterY() / m_oldFactors[1];
Expand Down

0 comments on commit 556d54b

Please sign in to comment.