ij.gui.ImageCanvas Java Examples

The following examples show how to use ij.gui.ImageCanvas. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IJHistogramWindow.java    From thunderstorm with GNU General Public License v3.0 6 votes vote down vote up
private void createListeners() {
    //IJ.log("createListeners");
    if(srcImp == null) {
        return;
    }
    ImageCanvas canvas = srcImp.getCanvas();
    if(canvas == null) {
        return;
    }
    canvas.addMouseListener(this);
    canvas.addMouseMotionListener(this);
    canvas.addKeyListener(this);
    ImagePlus.addImageListener(this);
    Font font = live.getFont();
    live.setFont(new Font(font.getName(), Font.BOLD, font.getSize()));
    live.setForeground(Color.red);
}
 
Example #2
Source File: DisplayCanvas.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
/** Enable zooming out up to the point where the display becomes 10 pixels in width or height. */
protected double getLowerZoomLevel2(final double currentMag) {
	// if it is 1/72 or lower, then:
	if (Math.abs(currentMag - 1/72.0) < 0.00000001 || currentMag < 1/72.0) { // lowest zoomLevel in ImageCanvas is 1/72.0
		// find nearest power of two under currentMag
		// start at level 7, which is 1/128
		int level = 7;
		double scale = currentMag;
		while (scale * srcRect.width > MIN_DIMENSION && scale * srcRect.height > MIN_DIMENSION) {
			scale = 1 / Math.pow(2, level);
			// if not equal and actually smaller, break:
			if (Math.abs(scale - currentMag) != 0.00000001 && scale < currentMag) break;
			level++;
		}
		return scale;
	} else {
		return ImageCanvas.getLowerZoomLevel(currentMag);
	}
}
 
Example #3
Source File: DisplayCanvas.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
protected double getHigherZoomLevel2(final double currentMag) {
	// if it is not 1/72 and its lower, then:
	if (Math.abs(currentMag - 1/72.0) > 0.00000001 && currentMag < 1/72.0) { // lowest zoomLevel in ImageCanvas is 1/72.0
		// find nearest power of two above currentMag
		// start at level 14, which is 0.00006103515625 (0.006 %)
		int level = 14; // this value may be increased in the future
		double scale = currentMag;
		while (level >= 0) {
			scale = 1 / Math.pow(2, level);
			if (scale > currentMag) break;
			level--;
		}
		return scale;
	} else {
		return ImageCanvas.getHigherZoomLevel(currentMag);
	}
}
 
Example #4
Source File: IJHistogramWindow.java    From thunderstorm with GNU General Public License v3.0 5 votes vote down vote up
private void removeListeners() {
    //IJ.log("removeListeners");
    if(srcImp == null) {
        return;
    }
    ImageCanvas canvas = srcImp.getCanvas();
    canvas.removeMouseListener(this);
    canvas.removeMouseMotionListener(this);
    canvas.removeKeyListener(this);
    ImagePlus.removeImageListener(this);
    Font font = live.getFont();
    live.setFont(new Font(font.getName(), Font.PLAIN, font.getSize()));
    live.setForeground(Color.black);
}
 
Example #5
Source File: FakeImageWindow.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
public FakeImageWindow(ImagePlus imp, ImageCanvas ic, Display display) {
	super(imp.getTitle());
	this.display = display;
	ij = IJ.getInstance();
	this.imp = imp;
	this.ic = ic;
	imp.setWindow(this);
	WindowManager.addWindow(this);
}
 
Example #6
Source File: RoiPicker.java    From Stitching with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Functional method of the RoiPicker. Determines which Rois match the x,y
 * coordinates of the received MouseEvent and the C,Z,T coordinates of the
 * active image. The user can cycle through these Rois with repeated clicks.
 */
@Override
public void mouseReleased(MouseEvent e) {
	ImageCanvas source = (ImageCanvas) e.getSource();
	if (source != canvas) {
		// We changed image window. Update fields accordingly
		ImageWindow window = (ImageWindow) source.getParent();
		imp = window.getImagePlus();
		canvas = source;
	}
	// Convert global coords to local
	double x = canvas.offScreenXD(e.getX());
	double y = canvas.offScreenYD(e.getY());
	// Get the RoiManager
	RoiManager rm = RoiManager.getInstance();
	if (rm == null) return;

	Roi[] rois = rm.getRoisAsArray();
	// Get the active ImagePlus's current z,c,t coords
	int[] position = imp.convertIndexToPosition(imp.getCurrentSlice());

	Set<Integer> matchedSet = new HashSet<Integer>();
	List<Integer> matchedIndices = new ArrayList<Integer>();

	// generate list of all rois containing x,y and matching the ImagePlus's
	// position
	for (int i = 0; i < rois.length; i++) {
		Roi r = rois[i];
		// Check position
		if (containsPoint(r, position, x, y)) {
			// Matched. Add to the matched set and list
			Integer index = i;
			matchedSet.add(index);
			matchedIndices.add(index);
		}
	}

	// If we discovered the currently known roi set, display the next roi in
	// the series
	if (same(roiSet, matchedSet)) {
		incrementIndex();
	}
	else {
		// otherwise, update the cached indices and display the union of the rois
		roiSet = matchedSet;
		roiIndices = matchedIndices;
		roiIndex = roiIndices.size();
	}

	// Perform the roi selection
	if (matchedIndices.size() > 0) selectRois(rm);
}