Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package hu.kazocsaba.imageviewer;
  
  import javax.swing.JLabel;
A component for displaying a series of images. Supports paging through GUI as well as setting the current position via function setPosition(int). When the position is changed, the positionChanged() method is called. Subclasses should override this method to update the image according to the new position.

Author(s):
Kazó Csaba
 
 public class ImageSequenceViewer {
 
 	private final ImageViewer imageViewer;
 	private int number,  position;
 	private JLabel locationLabel;
 	
 	private JPanel panel=new JPanel(new BorderLayout()) {
 
 		public void addNotify() {
 			super.addNotify();
 		}
 	};

Creates a new sequence viewer that can display the specified number of images.

Parameters:
number the number of images
Throws:
java.lang.IllegalArgumentException if the number is negative
 
 	public ImageSequenceViewer(int number) {
 		this(number, 0);
 	}

Creates a new sequence viewer that can display the specified number of images.

Parameters:
number the number of images
startPos the initial position of the viewer
Throws:
java.lang.IllegalArgumentException if the number is negative or the starting position is not valid
 
 	public ImageSequenceViewer(int numberint startPos) {
 		if (number <= 0 || startPos < 0 || startPos >= number)
 			throw new IllegalArgumentException();
 		 = new ImageViewer();
 		this. = number;
 		this. = startPos;
 		
 
 		 = new JButton(">");
 		 = new JButton("<");
 		JPanel locationPanel = new JPanel(new FlowLayout());
 		locationPanel.add();
 		locationPanel.add(createLocationDefinition());
 		locationPanel.add();
 
 
 			public void actionPerformed(ActionEvent e) {
 			}
 		});
 
 			public void actionPerformed(ActionEvent e) {
 			}
 		});
 
 		.add(locationPanel.);
 
 	}

Returns the Swing component for this sequence viewer.

Returns:
the component
 
 	public JComponent getComponent() {
 		return ;
 	}

Called when the current position of the viewer has changed. The default implementation does nothing. Subclasses should override this method to update the image.

This method is not called from the constructor, but it is called before the viewer is made visible, so subclasses can safely use this method to set the initial image.

	protected void positionChanged() {
	}
		return ;
	}

Sets the position of the viewer.

Parameters:
pos the new position of the viewer
Throws:
java.lang.IllegalArgumentException if the position is not valid
	public void setPosition(int pos) {
		if (pos < 0 || pos >= )
			throw new IllegalArgumentException("Position " + pos + " out of range");
		 = pos;
	}

Returns the current position of this image sequence shower.
	public int getPosition() {
		return ;
	}

Creates and returns the component that displays the current position to the user. The default implementation creates a JLabel.

Returns:
the location component
	}

Called when the current position changes to update the location component.

Parameters:
pos the current position
	protected void updateLocationDefinition(int pos) {
		.setText(String.format("%d/%d"pos + 1, ));
	}
New to GrepCode? Check out our FAQ X