Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package hu.kazocsaba.imageviewer;
  
  import java.awt.Component;
  import java.awt.Dimension;
  import java.awt.Rectangle;
A component showing an image as well as an arbitrary number of overlays.

Author(s):
Kazó Csaba
 
 class LayeredImageView  {
 	private final ImageComponent theImage;
 	private final JLayeredPane layeredPane;
 	
 	public LayeredImageView(ImageComponent theImage) {
 		this. = theImage;
 		.add(theImage, Integer.valueOf(0));
 	}
Returns the component for this layered view.

Returns:
the Swing component for this view
 
 	public JComponent getComponent() {return ;}

Adds an overlay as the specified layer.

Parameters:
overlay the overlay to add
layer the layer to add the overlay to; higher layers are on top of lower layers; the image resides in layer 0
 
 	public void addOverlay(Overlay overlayint layer) {
 		if (overlay==nullthrow new NullPointerException();
 		overlay.addOverlayComponent(c);
 		.add(c, Integer.valueOf(layer));
 	}
Removes an overlay from the image viewer.

Parameters:
overlay the overlay to remove
Throws:
java.lang.IllegalArgumentException if the overlay is not in the image viewer
 
 	public void removeOverlay(Overlay overlay) {
 		if (overlay==nullthrow new NullPointerException();
 			if (c instanceof OverlayComponent && ((OverlayComponent)c).==overlay) {
 				return;
 			}
 		}
 		throw new IllegalArgumentException("Overlay not part of this viewer");
 	}
 	private class ScrollableLayeredPane extends JLayeredPane implements Scrollable {
 
 		public int getScrollableUnitIncrement(Rectangle visibleRectint orientationint direction) {
 			return 10;
 		}
 
 		public int getScrollableBlockIncrement(Rectangle visibleRectint orientationint direction) {
 			return 50;
 		}
 
 		/*
 		 * The getScrollableTracksViewportXxx functions below are used by
 		 * javax.swing.ScrollPaneLayout to determine whether the scroll bars should
 		 * be visible; so these need to be implemented.
 		 */
 		public boolean getScrollableTracksViewportWidth() {
 		}
 
 		public boolean getScrollableTracksViewportHeight() {
 		}
 		
 		/*
 		 * The getPreferredScrollableViewportSize does not seem to be used.
 		 */
 				return getPreferredSize();
 			else
				return ((JViewport)javax.swing.SwingUtilities.getAncestorOfClass(JViewport.classthis)).getSize();
		}
	}
New to GrepCode? Check out our FAQ X