Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package hu.kazocsaba.imageviewer;
Utility methods for image viewers.

Kazó Csaba
public final class ImageViewerUtil {
Private constructor.
	private ImageViewerUtil() {}
A property change listener that synchronizes the display-related properties of two image viewers.
	private static class PropertySynchronizer implements PropertyChangeListener {
		private final ImageViewer v1,v2;
			this. = v1;
			this. = v2;
		public void propertyChange(PropertyChangeEvent evt) {
			ImageViewer target=source== ?  : ;
			if ("statusBarVisible".equals(evt.getPropertyName())) {
else if ("resizeStrategy".equals(evt.getPropertyName())) {
else if ("zoomFactor".equals(evt.getPropertyName())) {
else if ("pixelatedZoom".equals(evt.getPropertyName())) {
else if ("interpolationType".equals(evt.getPropertyName())) {
Synchronizes the view state of multiple image viewers with respect to scroll position and resize strategy, and other properties affecting display. For this to work correctly, the viewers should always have the same size.

first the first viewer
others the other viewers
	public static void synchronizeViewers(ImageViewer firstImageViewer... others) {
		for (ImageViewer otherothers) {
			if (other!=first) {
				new PropertySynchronizer(firstother);

Synchronizes the PixelInfoStatusBars associated with the viewers. Viewers with a different or null status bar are ignored. When this function returns, the PixelInfoStatusBars among the viewer status bars will share the same PixelModel, and thus display the same pixel.

The default status bar of ImageViewer is a PixelInfoStatusBar, so this function can be used to synchronize the default status bars of viewers.

viewers the viewers
	public static void synchronizePixelInfoStatusBars(ImageViewer... viewers) {
		PixelModel model=null;
		for (ImageViewer viewerviewers) {
			StatusBar bar=viewer.getStatusBar();
			if (bar instanceof PixelInfoStatusBar) {
				if (model==null)
New to GrepCode? Check out our FAQ X